Sometimes you might want to change not only the granularity of a visualization’s X-axis, but the range as well. This is possible using parameters and Switch statements.
-
Create a list control parameter called
→[Date-Granularity]
with the following settings: -
Add a table (with a date column) to your Workbook on a hidden page, then:
- Group by [Date] to get [Day of Date] (Sigma will auto-truncate each date to day of date).
-
Create a child visualization from the parent table and use the following formulas in the X/Y axes:
-
X-axis:
Switch([Date-Granularity], "Daily (Last 90 Days)", [Day of Date], "Weekly (Last 6 Months)", DateTrunc("week_starting_sunday", [Day of Date]), "Monthly (Last 12 Months)", DateTrunc("month", [Day of Date]))
- The above will check if the
[Date-Granularity]
parameter is set to “Daily (Last 90 Days)”, “Weekly (Last 6 Months)”, or “Monthly (Last 12 Months)”. Then, it sets the X-axis values to be the dates truncated to the corresponding level (i.e., Day, Week, or Month).
- The above will check if the
-
Y-axis:
Switch([Date-Granularity], "Monthly (Last 12 Months)", SumIf([Cost], [Day of Date] >= DateTrunc("month", DateAdd("month", -12, Today()))), "Weekly (Last 6 Months)", SumIf([Cost], [Day of Date] >= DateTrunc("week_starting_sunday", DateAdd("month", -6, Today()))), SumIf([Cost], [Day of Date] >= DateAdd("day", -90, Today())))
- The above changes the Y-axis formula depending on which
[Date-Granularity]
setting is selected. Note that eachSumIf
statement returns the sum of the[Cost]
column wherever[Day of Date]
is after or equal to the minimum date that is X days/months before today.
- The above changes the Y-axis formula depending on which
-
-
Filter out the Nulls in the Y-axis column:
-
Right-click the Y-axis column and select “Filter”
-
Click the 3-dot kebab menu icon and de-select “Include nulls”
-
Voila!
This changes the minimum date and date granularity shown on the visualization.