One of our customers recently asked us how to make their dashboard open on the current week. “my data” they specified “contains future dates too. I would like to make sure that the dashboard opens on today’s week (e.g. week 36), rather than in the most recent data available in the database”. And lastly “further, I would like to still be able to select another week”.
So our goal is to build a dashboard that:
As with (almost!) anything, there is indeed a way to achieve this in Tableau. The dashboard below is an example of how this can be achieved: you can download the workbook from my Tableau Public profile to follow along!
To achieve this goal, we will need to create
To get started, we need to customize our date fields, so that they can be used in our week parameter. That is why we will create a “Week number” and a “Today’s week” calculated fields.
1. “Week number” calc
Firstly, we will need to create a calculated field that returns all the week numbers available in a year. Let’s call it “Week number” and use the following formula: datepart(‘week’, [insert date field name]). This field will return an integer.
2. “Today’s week” calc
Secondly, we will create a calculated field that returns the current week number, called “Today’s week” and with the following formula. This field will return an integer.
datepart(‘week’, today())
3. “Week” parameter
Once we have created the “Week number” and “Today’s week” calculated fields, we need to create a “Week” Parameter. Here is what it should look like:
To achieve these settings (and save yourself some confusion) follow the instructions below in the order presented:
N.B.: It is important to specify this choice at the end of the setting. This is because otherwise “When workbook opens” under List of values will overwrite your choice.
At this point, the dashboard should show only data for the week number of the current week.
However, if your database contains multiple year, the dashboard will show data from e.g. all available weeks 35 (week 35 2019, week 35 2020, etc). In order avoid this, and to allow the user to select which year they would like to look at, we are going to create the same calculated fields and parameters we just created, but this time for year instead of week.
datepart(‘year’,2025)
2. Create a “Current year” calculated field (similar to the “Today’s week” calc):
datepart(‘year’, TODAY())
3. Create a Years Parameter, similar to the ‘Week’ Parameter we created previously. The instructions are the same: set data type as integer, select Allowable value: list, select ‘When workbook opens’ and set it to “Years”, and lastly select “Current year” next to ‘Value when workbook open’
Congrats for making it so far! We just have a couple of tweaks left to achieve our goal.
if ([Week number] = [Week] and [Years] = [Year]) then [insert measure here] else null end
Wanna learn more about Tableau or Alteryx? Do you want to use these tools to their full potential? Check out our trainings and consultancy services!