Google Data Studio自定义跨月日期对比周期配置问题求助
I totally get your frustration here—Google Data Studio's built-in "Previous Period" option works on a fixed day-count offset, which fails when you need a true "same day last month" match (especially when your date range crosses a month boundary, like your 6/28-7/27 example where it drops 5/28). Let's break down two reliable solutions to get this working:
Solution 1: Adjust Dates at the Data Source (SQL)
If you're using a SQL-based data source (like BigQuery, PostgreSQL, etc.), precomputing the matching "previous month same day" date directly in your query is the most robust approach—even handling edge cases where the current date doesn't exist in the previous month (e.g., March 31 → February 28/29).
Here's an example query snippet (adjust for your SQL dialect if needed):
SELECT date, -- Calculate exact same day last month, handling month-end edge cases CASE WHEN EXTRACT(DAY FROM date) > EXTRACT(DAY FROM LAST_DAY(DATE_SUB(date, INTERVAL 1 MONTH))) THEN LAST_DAY(DATE_SUB(date, INTERVAL 1 MONTH)) ELSE DATE_SUB(date, INTERVAL 1 MONTH) END AS previous_month_date, -- Include your metrics here sessions, revenue, conversions FROM your_dataset.your_table
Once you have this previous_month_date field in your Data Studio data source:
- Add both
dateandprevious_month_dateas dimensions - Create calculated metrics to compare current vs. previous values (e.g.,
Current Revenue=revenue,Previous Revenue=SUM(revenue) OVER (PARTITION BY previous_month_date)) - Use your date range control on the
datefield, and theprevious_month_datewill automatically align to the correct prior period.
Solution 2: Use Blended Data in Data Studio (No SQL Changes)
If you can't modify the underlying SQL, use Data Studio's blended data feature to align the previous month's data to your current date range:
- Duplicate your data source:
- Create two copies of your original data source: name one
Current Periodand the otherPrevious Period.
- Create two copies of your original data source: name one
- Add an adjusted date field to the Previous Period source:
- In the
Previous Perioddata source, create a calculated field namedadjusted_datewith this formula:
This shifts all previous month dates forward by one month (e.g., 5/28 becomes 6/28, 6/27 becomes 7/27).DATE_ADD(date, INTERVAL 1 MONTH)
- In the
- Blend the two data sources:
- Go to Resources > Manage blended data and create a new blend.
- Add both
Current PeriodandPrevious Periodas data sources. - Set the join key to
date(fromCurrent Period) andadjusted_date(fromPrevious Period).
- Build your report:
- Use the blended data source in your charts.
- When you set your date range to 6/28-7/27, the blend will automatically pull the current data for those dates and the matching previous month data (5/28-6/27) aligned to the same date labels.
Why the Built-in "Previous Period" Fails
The default option calculates the prior period by subtracting the total number of days in your selected range from the start date. For your 30-day range (6/28-7/27), it subtracts 30 days from 6/28 to get 5/29, which skips the first day of your desired prior period. The solutions above avoid this by aligning each date individually to its exact counterpart in the previous month.
内容的提问来源于stack exchange,提问作者André Cordeiro

