Swap different views on a single sheet
Written by: Ivett Kovács
![Swapping views on a sheet](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F78628d91c1dacc51f331e177780072a88b4a2e9f-1200x719.gif%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=75)
Learn how to reveal and hide different aspects of information on a single sheet using a parameter in Tableau. Follow this step-by-step guide and take your visualization to the next level!
A quick note: This post was originally published some time ago on DataViz.Love, our old blog. We have moved it here for preservation with the approval of the author(s).
I am sure everyone knows and have already used the view/sheet selection trick controlled by a parameter in one of their own Tableau projects. I was wondering if we could reveal/hide different aspects of the information on a single sheet.
Let me show an example.
![Gif of view swapping](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F78628d91c1dacc51f331e177780072a88b4a2e9f-1200x719.gif%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
If you swipe the line on this visualization you will be able to change the view. You can reveal/hide the different layouts. You can compare individual data points on a simple bar chart and at the same time, you can simultaneously compare sales totals and notice sharp changes at the segment level on a stacked bar chart.
Step #1: Make a Bar Chart
Connect to the Superstore data and build a simple bar chart that displays sales per month.
- Put the Continous Month(Order Date) to Columns
- Put Sales to Rows
![Making a bar chart](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F7a7bd21c2437bfde0340195720ff5c00dc88f97c-1362x976.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #2: Create a parameter based on the x-axis
Let’s create the parameter that will help Tableau to change the two views. This Parameter selection will be based on the x-axis. In this case, I will refer to the Month(Order Date) field.
- Set the Minimum and Maximum range
- Step size = 1 Month
![Create a parameter based on the X-axis](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Ff2f5156b1d72d633d5a4379d64bd1e9a3d5f535d-1186x994.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #3: Modify the bar chart based on the value of date parameter
Bar Chart
IF DATETRUNC(‘month’, [Order Date])>=[Date Parameter]
THEN [Sales]
ELSE 0
END
- Replace the SUM(Sales) field on Rows to this Bar Chart calculation
![Modify the bar chart based on the value of the date parameter](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Fc87b43af82327bcaf6647b527be9ced5382094ae-662x152.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #4: Add the date parameter to the chart as a reference line
![Add the date parameter to the chart as a reference line](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F64bd798be833abde68cfab954b535ad9fdd13536-1200x1046.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
The result is:
![Result of adding the reference line](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F4d7f7a1dc8fef5c737872b0c05b8f527f7330fa3-1840x1072.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
STEP #4: DEFINE THE STACKED VIEW
Stack Bar Chart
IF DATETRUNC(‘month’, [Order Date])<[Date Parameter]
THEN [Sales]
ELSE 0
END
- Add this Stacked Bar Chart calculation next to the Bar Chart field on Rows
- Make it Dual Axis.
![Defining the stacked view](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F8063f4b5b80207a1a4e0282cab52173b221ec7bd-714x358.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
- Syncronize them
- Add Segment to Color Mark
![Adding Segment to Color](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Fad396d5c960bcaac164b316dd148d08dac3d5d6f-462x656.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
And enjoy your result!
If you have any questions, reach out on Twitter @IvettAlexa