Skip to main content

Free Time Comparison Case Study

Requirement Background: Sometimes users need to manually select a time range and compare it with another free time range data, such as comparing this year's Spring Festival holiday with last year's Spring Festival holiday, or last year's Double 11 and the year before's Double 11 promotion periods have different durations, requiring comparison of data from the two Double 11 promotion periods. For such situations, it's impossible to use the system's built-in year-over-year and month-over-month functions, and manual specification of comparison date ranges is needed.

Function Used: Global Parameters

Implementation Method:

1. Create 4 time-type global parameters, respectively used to obtain the start and end dates of the current period and comparison period. It's recommended to name them in pairs for easy use, such as begin_date1, end_date1, begin_date2, end_date2.

image.png

2. In table cards, create a new calculated field using case when or if functions to determine dates between begin_date1 and end_date1 as "Current Period", and dates between begin_date2 and end_date2 as "Comparison Period". Then drag to the dimension column or comparison column as needed, and also drag to the filter column, checking "Current Period" and "Comparison Period".

image.png

3. Create a new calculated field "Days", calculating the number of days for "Current Period" and "Comparison Period". Drag to the dimension column or value column as needed, if placed in the value column, aggregation method select "No Processing".

image.png

4. Create the report and save it. If the edit page shows no data, you can temporarily set default values in "Chart Properties" - "Parameter Default Values" on the right side of the page to ensure there is data for preview and verification.

image.png

5. Create 4 parameter filters on the page, respectively using the 4 time parameters referenced in the card. After saving, they will automatically link to all cards on the current page that use the same parameters.

image.png

If you need to link to other cards on the page that don't use global parameters, you need to use date filters instead and manually select the corresponding time parameters in the card in the linkage interface.

image.png

6. The final effect is as follows. If the above functions need to be reused across multiple cards, it's recommended to directly save as a card, then modify the chart type to create other visualization effects.

image.png