A marketing mix model is only as honest as the spreadsheet you feed it. Most failed MMM projects are not modelling failures. They are data failures that nobody noticed until the results looked strange.
This guide builds the weekly dataset step by step, using the GA4 BigQuery export for the outcome and an ad cost table for spend.
What the model needs
- An outcome. Weekly revenue or orders, defined once and measured the same way across the whole history.
- Media variables. Weekly spend for every paid channel. Add impressions where you have them, because spend alone hides changes in price.
- Controls. Promotions, price changes, holidays, product launches, stockouts and any event that moved sales without media.
- History. Two to three years of weekly rows is the commonly recommended minimum, so each season appears at least twice.
Step 1: choose the grain
Use weeks that start on Monday. Daily data adds noise and rarely improves a model, while monthly data leaves too few rows. Every source must use the same week boundary, otherwise spend and revenue slide against each other by a day or two and the carryover estimates drift.
Step 2: build the outcome and spend in BigQuery
The query below aggregates purchases from the GA4 export and ad costs from a daily cost table into one row per week. The date range starts on a Monday and ends on a Sunday, so no partial weeks sneak in.
WITH revenue AS (
SELECT
DATE_TRUNC(PARSE_DATE('%Y%m%d', event_date), WEEK(MONDAY)) AS week_start,
SUM(ecommerce.purchase_revenue) AS revenue,
COUNT(*) AS orders
FROM `my-project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20230102' AND '20261129'
AND event_name = 'purchase'
GROUP BY week_start
),
spend AS (
SELECT
DATE_TRUNC(date, WEEK(MONDAY)) AS week_start,
SUM(IF(channel = 'google_ads', cost, 0)) AS spend_google,
SUM(IF(channel = 'meta_ads', cost, 0)) AS spend_meta,
SUM(IF(channel = 'tiktok_ads', cost, 0)) AS spend_tiktok
FROM `my-project.marketing.daily_ad_costs`
GROUP BY week_start
)
SELECT *
FROM revenue
LEFT JOIN spend USING (week_start)
ORDER BY week_start;
Replace the project, dataset and channel names with your own. If a channel did not run in some weeks, wrap its column in COALESCE so the model sees zero spend and not a missing value.
A note on the outcome. Decide whether the model explains gross revenue, net revenue after refunds, or margin, and keep that choice fixed for the entire history. Mixing definitions across years creates a fake trend. For lead generation businesses, use qualified leads or closed deals instead of raw form fills, shifted to the week the lead was created.
Step 3: add controls
Keep promotions and events in a small hand-maintained list with one row per week: a promotion flag, the discount depth, and a holiday marker. Join it to the weekly query on week_start. Be specific about what each flag means, because a vague "campaign" flag quietly absorbs effects that belong to media. Add impressions or reach for channels such as television and video as well, since the same spend buys different exposure when prices change.
Step 4: check the data before modelling
- No gaps. Every week between the first and last must exist exactly once.
- Spend reconciles. Weekly totals should match ad platform invoices within a small margin.
- Tracking outages. A broken tag or a consent change looks like a demand drop. Mark those weeks with a control variable so the model does not blame media.
- Collinearity. Channels that always move together cannot be separated, so inspect their correlation first.
import pandas as pd
df = pd.read_csv("mmm_weekly.csv", parse_dates=["week_start"])
assert df["week_start"].is_monotonic_increasing
assert (df["week_start"].diff().dropna() == pd.Timedelta(days=7)).all(), "gap in weeks"
print(df.filter(like="spend_").corr().round(2))
When two channels correlate above roughly 0.8, consider merging them or running a short pause test on one, which creates the variation the model needs.
Clean weekly data takes a day to build and saves weeks of confusing results. Treat the spreadsheet as the model's first draft, and fix it before anyone fits a single curve.
Want a stronger data analyst role or a raise? Grab the FREE Product Analyst Playbook and get the exact roadmap to your next offer.


