A marketing mix model wants one row per week: the spend and an exposure metric for each paid channel, and one KPI. To get there from etlmcp's daily rows in PostgreSQL, convert every amount into one currency first, then group the days into weeks in SQL with one spend column and one impressions column per network, fill weeks without spend with zero, and take the KPI from Shopify's net sales or order count. Before you fit anything, check that the table holds at least two years of weeks, and three for a national model.
What the delivered table looks like
etlmcp writes one row per day and per account, campaign or ad, depending on the pipeline. The PostgreSQL destination creates the table on the first run with the standard columns, among them date (type date), network, cost, impressions, clicks and currency; the metrics are double precision. Values a platform reports beyond the standard columns land in columns named extra.<name>. Those names keep their dot, so in SQL you must write them in double quotes, for example "extra.net_sales".
When the connectors are available, an ad network's rows carry its key in network (meta, google and so on). A Shopify row carries shopify, leaves cost and impressions empty and holds the store's figures in extras, among them "extra.orders", "extra.net_sales" and "extra.revenue", which is the same figure as net sales. Shopify writes a row only for a store-local date with at least one counted order; test and cancelled orders are left out.
The recipe below assumes every pipeline loads into one table, public.marketing_daily. Pipelines can share a table: each run deletes and rewrites only its own pipeline's rows for the dates it covers. If you keep one table per pipeline, UNION ALL them first.
Step 1: one currency
cost arrives in each ad account's own currency, never converted, and every row says which currency in currency. A Shopify row is in the store's currency. Summing a euro account and a dollar account gives a meaningless number. Check what you have:
SELECT network, currency, COUNT(*) AS days, MIN(date) AS first_day, MAX(date) AS last_day
FROM public.marketing_daily
GROUP BY network, currency
ORDER BY network, currency;
If more than one currency comes back, add an fx rule to each pipeline that needs it. One rule converts one column: one for cost, and on the Shopify pipeline one each for extra.net_sales and any other amount you model. The rule also writes the target currency into currency, so the query above confirms the change. Its rates are fixed numbers, the same for every day, which is a simplification over two or three years; if you need dated rates, keep the native currency and join a rates table of your own in SQL instead.
Step 2: weekly media columns, zero-filled
In PostgreSQL, date_trunc('week', …) gives the start of the week. That is Monday, the ISO week start. If your business counts weeks from Sunday, use date_trunc('week', date + 1)::date - 1. Pick one start and use it for media and KPI alike, or spend and sales land in different rows.
generate_series with an interval step lists every week in the range, so a week in which a channel spent nothing still gets a row. Meridian's data guide asks for a complete table with no gaps and says to fill a media channel's missing values with zero when it was not running; COALESCE(…, 0) does that.
CREATE OR REPLACE VIEW public.mmm_weekly AS
WITH weeks AS (
SELECT generate_series(
date_trunc('week', DATE '2023-01-02'),
date_trunc('week', current_date) - INTERVAL '1 week',
INTERVAL '1 week')::date AS week_start
),
media AS (
SELECT date_trunc('week', date)::date AS week_start,
SUM(cost) FILTER (WHERE network = 'meta') AS meta_spend,
SUM(impressions) FILTER (WHERE network = 'meta') AS meta_impressions,
SUM(cost) FILTER (WHERE network = 'google') AS google_spend,
SUM(impressions) FILTER (WHERE network = 'google') AS google_impressions
FROM public.marketing_daily
WHERE network IN ('meta', 'google')
GROUP BY 1
),
kpi AS (
SELECT date_trunc('week', date)::date AS week_start,
SUM("extra.net_sales") AS net_sales,
SUM("extra.orders") AS orders
FROM public.marketing_daily
WHERE network = 'shopify'
GROUP BY 1
)
SELECT w.week_start,
COALESCE(m.meta_spend, 0) AS meta_spend,
COALESCE(m.meta_impressions, 0) AS meta_impressions,
COALESCE(m.google_spend, 0) AS google_spend,
COALESCE(m.google_impressions, 0) AS google_impressions,
k.net_sales,
k.orders
FROM weeks w
LEFT JOIN media m USING (week_start)
LEFT JOIN kpi k USING (week_start)
ORDER BY w.week_start;
Change the first date to your first full week, and add a spend and an impressions pair for each further network. The last row is the most recent complete week, so a half-filled current week never enters the model. Keep impressions as the exposure column: Robyn's guide prefers exposure metrics such as impressions as the model's inputs and advises against clicks, while still asking for spend to work out return.
Step 3: the KPI
Shopify's extra.net_sales is product sales after discounts, returns and order edits, without tax and shipping; extra.orders counts orders. Choose one as the KPI. Both add up across weeks, which Meridian requires of a KPI. Do not zero-fill the KPI column the way you did media: Meridian's guide warns that zero-filling the KPI or controls skews the estimates and suggests filling a real gap from neighbouring weeks or the average instead. A week with no Shopify rows may be a store that sold nothing, or a sync that never ran, so look at it before you fill it.
Step 4: check the history
Meridian asks for at least two years of weekly data for a geo model and three for a national one; Robyn's guide asks for at least two years of weekly data. Count the weeks each source really covers:
SELECT network,
COUNT(DISTINCT date_trunc('week', date)) AS weeks,
MIN(date) AS first_day
FROM public.marketing_daily
GROUP BY network;
Two years is about 104 weeks, three about 156. A sync you start by hand may cover at most 366 days and may not start before your plan's history: Free keeps 30 days, Agency 730 and Scale 3650. To fill older years, run one backfill per year. Shopify shares only recent orders unless the app is approved to read all orders, so check Shopify order history before you plan on years of sales.
The view recalculates each time you query it, so the weeks that routine syncs re-pull and restate flow into the model's input without another step.