This query compares the sessions of the last 7 days to the previous 7 days aggregated by campaign_name
. This query demonstrates the use of a concept that can be used with any dimension and metric\s, comparing different values of the metric based on different values of time or a given dimension.
SELECT
campaign_name,
SUM(
CASE WHEN date_start >= current_date - 7
AND date_start < current_date THEN clicks END
) last_7,
SUM(
CASE WHEN date_start >= current_date - 14
AND date_start < current_date - 7 THEN clicks END
) previous_7
FROM
public."facebook-ads" -- Table name might be different based on Schema and Destination settings in the data source
WHERE
date_start >= current_date - 14
AND date_start < current_date
GROUP BY
1
ORDER BY
1
Column | Description |
---|---|
campaign_name |
Facebook Ads campaign name |
last_7 |
Values for last 7 days |
previous_7 |
Values for previous 7 days |