- Bernard K
How to keep x-axis range after filtering in Tableau
Updated: Nov 8, 2022
Anytime you filter data, the x-axis range changes to match the current values displayed in the view. For example, in this view the x-axis range when no filter is applied is 0 to 700k, however, when we apply segment as a filter – the axis changes to ‘0-300k’ for consumer segment, ‘0-250k’ for corporate segment and ‘0-160k’ for home office segment.
What can we do to keep the initial x-axis range when someone filters the data?
We can do that by adding a fixed axis range. To do that,
Right click on the axis >> Edit Axis…
On the pop-up menu, change the range from ‘Automatic’ to ‘Fixed’ which will fix the axis range from a start value to an end value (note you can input these values as you desire).
Note now when a filter is applied the x-axis range does not change – remains to be ‘0 to 700k’.
Keeping x-axis range after filter for multiple measures.
Note the above example doesn’t hold for cases where multiple measures are represented in the x-axis. For example, in this case am using a parameter to choose which measure is used in the view.
For such cases, you will note that by fixing the axis range will distort how other measures are interpreted. For example, if we fix the axis range like in the previous case, you will note that when we change the measure applied in the view from ‘Sales’ to ‘Profit Ratio’, the view will disappear. This is because the Profit Ratio values are too small to be visible in that range.
So, what should we do?
The solution to this problem is, first create a calculation that will compute the windows maximum value for each measure used to create the view using the formula below.
(Note, for my case active parameter is the calculation that contains the measure selected in the parameter – measure used to create the view).
Drag this computation ‘Windows max value’ to the detail shelf.
Add it as a reference line as shown below.
(Chose none under ‘Label’, ‘Tooltip’ and ‘Line’ to ensure the reference line is invisible in the view).
Executing this, leaves us with a view in which the x-axis range is recalculated for every measure applied in the view – while ensuring this x-axis range doesn’t change when the view is filtered by segment.
See the views when ‘Sales’ and ‘Profit’ are used as measures in the view.
I hope this article was helpful to you. To receive more of the Tableau tips, kindly join our mailing list by subscribing below.
If you like the work we do and would like to work with us, drop us an email on our Contacts page and we’ll reach out!
Thank you for reading!