Using a Parameter to Flip Between Days, Months and Years on Your Worksheet

by Jeremy Kneebone

It’s really easy to create a viz that allows the user to flip between different kinds of dates. This example uses Superstore data, and gives the sum of sales over time. Follow these steps:

  1. Drag SUM(Sales) to rows.
  2. Create a parameter called ‘Select Date Part’. Set the data type to string, allow a list and type in your own list with values day, week and month, like below (don’t use speech marks). Click ‘Ok’ and display the parameter on the view.

  1. Now create a calculated field, as below, with the DATETRUNC function, the parameter and your date field. The DATETRUNC function will allow you to use a continuous date field in your view, and the parameter will allow you to change exactly which date part you are using.

 

  1. Drag your new calculated field to Columns. It won’t look right initially.
  2. Here’s the bit you might not figure out on your own – click on the drop-down menu for your calculated field pill on Columns, and select Exact Date from the menu.

And you should see a line graph by the date part you’ve selected. Selecting days, months or years in the parameter will change the type of date used in the view.