Monday Minis: Dynamically Show/Hide Parameter so it Only Appears When Relevant

I was recently working with a client who had a need to visualize a metric 1 for a geographic area compared to either metric 2 for the same geographic area or metric 1 for a comparison geographic area. A user would choose which comparison they wanted from a parameter (primary geographic area metric 2 or secondary geographic area metric 1). However, when the client selected the first option (comparing metric 1 and 2 for the same geographic area), they didn’t want the comparison selection parameter to show because it didn’t have any relevance. So we needed a way to essentially “hide” the parameter and only show it when it was needed.

So imagine we are using Superstore in Tableau. I want a user to be able to view Sales for a selected State, let’s say Ohio, compared to that same state’s profit and I have parameters to select the State and change the comparison. As noted, we also need users to be able to select the comparison State when relevant. We would see something like this with all three parameters. You can see the last one says Pennsylvania, but that state isn’t even in the view, so it’s a bit confusing. Ultimately, when the comparison measure is set to “Primary State Profit” we don’t want to see the comparison state parameter selection.

So how can we hide it? Well we can use collapsing worksheets and a bit of Tableau trickery. You can view and download the accompanying workbook here. Let’s go through the simple steps.

STEP 1. Create a hide parameter sheet

  • Create a Blank calculation that only includes quotations
  • Drag the Blank calculation onto text and onto rows, then format so no lines are in the view and it appears blank (remove tooltip)
  • Place the parameter that will essentially trigger if the second parameter shows or not onto filters and check off the value that will show the second parameter.

STEP 2: Containers

  • Drag out a horizontal container and place both the main parameter and the one that you want to show only when relevant (in this case the Comparison State) into it. Then place the Hide Parameter Sheet in between the two parameters.
  • Fix the width of the two parameters to each 1/3 of the total width of the container. Do not fix the width of the Hide Parameter Sheet.

STEP 3: Float the last parameter

  • Float a blank white object over the Hide Parameter Sheet
  • Float the parameter that will determine if the second parameter will show or not over the Hide Parameter Sheet and blank object.
  • Now when the parameter changes the Hide Parameter Sheet will disappear which will cause the second parameter to shift to the left and be obscured by the blank object and the triggering parameter.

Below you can see how the viz looks when the comparison state parameter isn’t needed. We only see the two that are relevant.

Upon changing the comparison parameter, the comparison state parameter appears as the Hide Parameter sheet expands and thus moving the parameter into view. Pretty slick right?

So that’s how you can hide a parameter without adding any additional clicks or show/hide containers, etc. That being said, Kevin Flerlage does have a blog post about that exact technique, so if you want to use buttons instead, you can check out his post here.

As always, let me know if you have questions!

Cheers,

Lindsay

One comment

Leave a Reply to POUYA Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s