When analyzing any data over time, it is important to understand the seasonality or natural ebbs and flows of the data. For many businesses, these patterns in the data can be seen all the way down to the individual days of the week. Occasionally, it may be important to toggle off certain weekdays to get a clear picture or story within an analysis.
In this blog, I will show you how to toggle weekends on and off from an analysis. As a bonus, I will also show you how to build a calendar view and parameterize the toggle to switch between different views.
How to Create a Calendar View in Tableau
To start things off, let’s set up a simple calendar view so we can see the toggle working. First, I am going to connect to the Sample – Superstore dataset and drag Weekday of Order Date to the Columns Shelf. Next, I will drag Week of Order Date to the Rows Shelf. These are both discrete date parts of Order Date. The easiest way to get them onto the view is to right-click and drag them to the corresponding shelf. This will open a selection screen where you can choose which date part you want to use.
To create the calendar view, we will now want to filter on a specific month. To do this I will drag Order Date to the Filters Shelf, choose Month / Year, and click Next.
In the next menu I will select November 2020 and click OK.
With our filter in place, our calendar view is starting to take shape.
Now I will right-click and drag Order Date to the Label property of the Marks Card. Then select DAY(Order Date) from the menu and click OK.
Next, I am going to drag Sales to the Color property of the Marks Card and change the mark type to Square.
To add a personal touch, I will right-click on the Day of Order Date pill and align the labels to the top right. I will also right-click on Week of Order Date on the Rows Shelf and hide the header. Last, I will expand the view by clicking and dragging the bottom of the chart and update my color palette.
How to Create a Weekend Toggle In Tableau
Now that our view is set up and we can clearly see the weekdays displayed, lets create a toggle that will NULL weekends. To begin, let’s create a new parameter by right-clicking in any blank space within the Data pane and selecting Create Parameter. In the dialog that appears, I will change the title to Weekday Toggle Parameter, change the data type to Boolean, and click OK.
This parameter will act as our toggle later on, but first we need to create a way for the user to assign which weekdays to toggle on and off. To do this I am going to right-click on Order Date, hover over Create, then select Custom Date. In the dialog that appears I will click the Detail dropdown and select Weekdays; then click OK.
Now I will right-click on the new custom date calculated field, hover over Create, and choose Set.
In the Create Set dialog, I will add Sunday and Saturday in my set, select the Exclude button, then click OK.
Now I will create one last set following the same steps, except this time I will include all weekdays in the set. The final setup should look like this:
✎ Related blog post: The Definitive Guide to Tableau Sets
To bring it all the together I am going to create a calculated field by right-clicking in any blank space on the Data pane and selecting Create Calculated Field. I will enter the following calculation then click OK.
IIF([Weekday Toggle Parameter]=TRUE,[Order Date Weekdays To Remove],[Order Date All Weekdays])
Last, we will drag our new calculation to the Filters Shelf, select True, and click OK. This completes our calendar view sheet and the initial setup.
Setting Up A Toggle Using Tableau Parameter Actions
Now we are ready to implement the toggle sheet. First, we need to create a new sheet that will be used for the toggle on the dashboard. I’m going to open a new sheet by clicking the New Sheet icon at the bottom of the Authoring interface. Next, I’ll create our last calculated field by right-clicking in any blank space in the Data pane, selecting Create Calculated Field, entering the following calculation, and clicking OK.
IIF([Weekday Toggle Parameter]=TRUE,FALSE,TRUE)
In our blank sheet, I will change the mark type to Shape, then drag the new Toggle calculated field to the Shape property of the Marks Card. For our toggle shape I will load in a toggle image for both an active and inactive state or for when our parameter is True versus False. To do this, I loaded some custom images to my repository but the sky is the limit for this step, so get creative!
► Related video: How To Make an Integrated Toggle Switch in Tableau
The final step is to add both sheets to a dashboard and set up a dashboard action. To do so, I will click the New Dashboard icon at the bottom of the Authoring interface and drag both sheets onto the view. With both sheets in the view, I am going to click Dashboard in the top navigation and select Actions. From the menu that appears, I will click Add Action, then Change Parameter. In the next dialog screen, I am going to select our toggle sheet as the source, change the target parameter to the Weekday Toggle Parameter, and choose our Toggle calculated field as the value to pass. Last, I will ensure the action runs on Select, click OK, and click OK again. The final setup should look like this.
► Related video: How to Use Tableau Parameter Dashboard Actions
Now if you click on the toggle image on the dashboard, we will see Saturday and Sunday get excluded from the view. One last tip; If you want to allow your user to choose which weekdays to remove, click on the calendar view sheet on the dashboard, then click on the arrow that appears within the gray border. From the menu, hover over Sets, and click the set you set up that excludes certain weekdays. This will show the user the list of weekdays that will be excluded when your toggle is True.
I’ve shown you how to toggle weekends on and off from a literal calendar view in Tableau, but this same technique can be applied to any chart type and/or complete dashboards!
Until next time,
Sr. Manager, Analytics Engineering