Ad Spend Pacing Forecasts in Snowflake with SQL

14 minutes to read
Get free consultation

 

Managing a digital advertising budget requires constant balancing. Spend quickly, and you risk exhausting your budget before the month ends. Spend slowly, and you lose valuable chances to reach your audience. Accurate, timely pacing information plays a crucial role in managing this challenge.

Many organizations currently pull data into spreadsheets and handle manual calculations. Imagine building a dynamic, automated ad spend forecast directly within your data warehouse instead.

Our goal is to guide you through this process. Leveraging the power of Snowflake and the flexibility of SQL allows you to transform your raw ad spend data into a predictive engine. This strategy centralizes your logic, scales effortlessly, and empowers marketing teams to make better decisions quickly. In this guide, we’ll walk through the steps from data preparation to building the final SQL query, which will serve as your single source of truth for ad spend pacing.

Why Forecast Ad Spend in Snowflake?

Before diving into SQL, it is important to understand the benefits behind this approach. Moving your forecasting logic into Snowflake is not just a technical task; it’s a strategic move with significant business advantages.

Step 1: Preparing Your Data

Reliable forecasts start with clean, well-structured data. Begin by creating a unified view of your ad spend across all platforms. We assume your raw data from ad sources is already loaded into Snowflake using a tool like Fivetran.

Create a single table or view including these key columns:

You can build this unified model using a Common Table Expression (CTE) or a materialized view in Snowflake. Below is a simplified example combining data from two different platform tables:

CREATE OR REPLACE VIEW UNIFIED_AD_SPEND AS (
  SELECT
    date AS report_date,
    'Google Ads' AS platform,
    campaign_name,
    cost AS spend
  FROM raw_google_ads_spend
  
  UNION ALL
  
  SELECT
    date_start AS report_date,
    'Facebook Ads' AS platform,
    campaign_name,
    spend
  FROM raw_facebook_ads_spend
);

With this view ready, you have a clean foundation to build your forecast.

Step 2: Building the Pacing Forecast with SQL

Now to the core: the SQL query calculating pacing and forecasting future spend. Using CTEs keeps the query clear and maintainable.

The pacing logic compares how much budget you’ve spent versus the time elapsed in the budget period.

Pacing Percentage = (Percentage of Budget Spent) / (Percentage of Time Elapsed)

A 100% result means you’re perfectly on track. Above 100% indicates over-pacing, and below 100% indicates under-pacing.

Here’s the complete SQL query:

-- Set the budget and the reporting period
-- For a real-world scenario, you might pull the budget from another table
WITH period_and_budget AS (
  SELECT
    DATE_TRUNC('month', CURRENT_DATE()) AS start_date,
    LAST_DAY(CURRENT_DATE(), 'month') AS end_date,
    10000 AS monthly_budget -- Your total budget for the period
),

-- Calculate key date metrics based on the current date
date_calculations AS (
  SELECT
    pab.start_date,
    pab.end_date,
    pab.monthly_budget,
    CURRENT_DATE() AS today,
    DATEDIFF('day', pab.start_date, pab.end_date) + 1 AS total_days_in_period,
    DATEDIFF('day', pab.start_date, CURRENT_DATE()) AS days_elapsed,
    DATEDIFF('day', CURRENT_DATE(), pab.end_date) AS days_remaining
  FROM period_and_budget AS pab
),

-- Aggregate the actual spend from our unified data view
actual_spend_to_date AS (
  SELECT
    SUM(spend) AS total_spend
  FROM UNIFIED_AD_SPEND
  WHERE report_date >= (SELECT start_date FROM period_and_budget)
    AND report_date < (SELECT today FROM date_calculations)
),

-- Calculate the forecast and pacing
final_forecast AS (
  SELECT
    dc.monthly_budget,
    astd.total_spend AS actual_spend,
    
    -- Avoid division by zero on the first day
    IFF(dc.days_elapsed > 0, astd.total_spend / dc.days_elapsed, 0) AS avg_daily_spend,
    
    -- Forecasted Spend = Actual Spend + (Avg Daily Spend * Days Remaining)
    actual_spend + (avg_daily_spend * dc.days_remaining) AS forecasted_total_spend,
    
    -- Pacing Calculation
    IFF(dc.days_elapsed > 0, (actual_spend / dc.monthly_budget) / (dc.days_elapsed / dc.total_days_in_period), 0) * 100 AS pacing_percentage
    
  FROM date_calculations AS dc
  CROSS JOIN actual_spend_to_date AS astd
)

SELECT
  monthly_budget,
  actual_spend,
  forecasted_total_spend,
  pacing_percentage
FROM final_forecast;

This query provides a clear report with four key metrics: your budget, actual spend to date, forecasted total spend by period end, and current pacing percentage.

Step 3: From Raw Numbers to Actionable Insights

The SQL query is your forecasting engine, but its real value lies in how you use the results. Connect the output directly to BI tools like Looker, Tableau, or Power BI. This lets you create dashboards that visualize your ad spend pacing, enabling your marketing team to quickly understand the data.

Visualizing this data helps your team instantly answer important questions:

Adopting this proactive approach to budget management marks a mature data strategy. It turns data from a reactive report into a proactive, decision-making tool—a central piece in building a Modern Data & Analytical Platform.

Conclusion

Manually exporting ad spend data to spreadsheets for forecasting is no longer necessary. Leveraging Snowflake and SQL lets you build a robust, automated pacing and forecasting system where your data already lives. This method is more efficient, scalable, and reliable.

We demonstrated how to unify your ad spend data and build a SQL query calculating pacing and forecasted spend. The key is putting actionable data into your marketing team’s hands, helping optimize campaigns and maximize budget impact. Start with one platform to validate the concept, then expand across all marketing channels.

Ready to transform your Snowflake data into a predictive powerhouse? Contact Stellans today to learn how our data experts can build custom forecasting and analytics solutions that drive real business growth.

Frequently Asked Questions

How is this different from the pacing reports inside Google Ads or Facebook Ads?
Platform-specific reports are useful but siloed. This Snowflake-based approach offers a holistic view across all your channels, giving you one source of truth for your total marketing budget rather than just one platform.

Can I use this for different budget periods, like quarterly or annually?
Definitely. This SQL query is designed for monthly periods, but you can adjust the DATE_TRUNC and LAST_DAY functions for other periods (e.g., ‘quarter’). Just ensure your budget input matches the new period.

What if my daily ad spend fluctuates wildly, such as on weekends?
This model uses a simple average daily spend. For more accuracy, you can enhance it with a moving average (AVG(spend) OVER (ORDER BY report_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)) to smooth fluctuations or develop different forecasts for weekend vs. weekday spend.

Does this require any special Snowflake features or a specific tier?
No. All functions used here (DATEDIFF, DATE_TRUNC, SUM, CTEs) are standard features available in all Snowflake versions. The solution is accessible and efficient for any standard Snowflake warehouse.

Article By:

https://stellans.io/wp-content/uploads/2024/06/telegram-cloud-photo-size-2-5364116417437360081-y-1-1.png
Roman Sterjanov

Data Analyst at Stellans

Related Posts

    Get a Free Data Audit

    * You can attach up to 3 files, each up to 3MB, in doc, docx, pdf, ppt, or pptx format.