How to display year, month, day, and hour on the x axis based on what the user selects in a Tableau dashboard or workbook?

  • Tableau FAQs
  • December 13, 2018
Get Started Transforming Your Data in Snowflake

Tableau makes it easy to select and modify date dimension aggregates when building a worksheet view. However, unless the end-user is viewing a separate sheet in Tableau Desktop, they cannot easily change the granularity of the date by a day, week, month, quarter, or year on their own in the dashboard.

To provide flexibility to change data granularity in a viz, we can create a parameter that includes each date granularity option (i.e., Day, Week, etc.). We also must create a calculated field that acts as the adjustable date aggregation value.

 

  • Create a Parameter with All Date Aggregations
  • Create a Calculated Field to Change Date Aggregations
CASE [DateLevels]

WHEN 'Day' THEN [DueDate]

WHEN 'Week' THEN DATETRUNC('week',[DueDate])

WHEN 'Month' THEN DATETRUNC('month',[DueDate])

WHEN 'Quarter' THEN DATETRUNC('quarter',[DueDate])

WHEN 'Year' THEN DATETRUNC('year',[DueDate])

END
  • CASE [DateLevels] – The CASE function evaluates expression, compares it to a sequence of values, value1, value2, etc., and returns a result. When a value that matches the expression is encountered, CASE returns the corresponding return value. If no match is found, the default return expression is used. If there is no default return and no values match, then Null is returned.WHEN ‘Day’ THEN [DueDate] – If Day is selected, then we show Details by dateWHEN ‘Week’ THEN DATETRUNC(‘week,’ [DueDate]) – Next, if a week is selected, then we use DATETRUNC to extract the date level from the DueDateWHEN ‘Month’ THEN DATETRUNC(‘month’,[DueDate]) – The same for the monthWHEN ‘Quarter’ THEN DATETRUNC(‘quarter’, [DueDate]) – The same for the quarterWHEN ‘Year’ THEN DATETRUNC(‘year’,[DueDate]) – And the same for YearEND – here we are finishing our expression
  • Use the New Date Aggregation Calculation in the View
  • Make the Date Aggregation Parameter Available to Users. Ensure you right-click on the Date Granularity parameter and choose “Show Parameter Control” so your end users can change the level of date aggregation.

Up Next:

Read How to use count and count distinct properly in Tableau?

Related Posts

Top 5 Snowflake tools for Analysts- talend

Top 5 Snowflake Tools for Analysts

  • Ndz Anthony
  • February 26, 2024