Ryan Sleeper
In this exclusive Playfair+ webinar, Ryan shares techniques for all skill levels that allow you to toggle anything in Tableau. Whether you are new to the software and trying to provide a better user experience or are an expert seeking a more advanced analysis, there are practical applications for everyone in this session.
Hi, this is Ryan with Playfair Plus, and in this webinar, Three Ways to Make Terrific Toggles in Tableau, I’ll be sharing three different techniques for making toggles, as well as three unique use cases. By the end of this video, you’ll be able to make the three different toggles on the screen here. The first is going to allow you to click a button to turn normalization on and off on a map, and that toggle is being used across multiple worksheets. So when the toggle is turned off, we’re seeing SUM of Sales. When the toggle is turned on, we’re seeing Sales Per Capita.
In the second example, I’ll show you how to toggle between a visualization and a raw crosstab of data with the click of a button. And in the third example, I’ll show you a technique called button swapping that allows you to swap in different images to show you what has been selected on a view.
Alright, well, let’s get started. Today, we’re talking about toggles. I thought it’d be a good place to start to first show you what I’m talking about when I’m talking about toggles. This is one of my favorite techniques in Tableau. There’s so many use cases of this.
There’s also so many techniques to even create a toggle. So in today’s webinar, I’m going to be showing you three different techniques. And because there are infinite use cases, I’ve got three brand new use cases that– so we’ll also talk a little bit of visual analytics strategy and how you can apply these three different techniques to make them applicable and relevant within your own business.
So a little bit of everything. This will be quite technical, but we have techniques for all different skill levels, whether you’re brand new to Tableau or very advanced. I’m going to show you three different techniques. And then for each one of those individual techniques, I will show you an individual use case.
But first, what am I talking about when we’re referring to toggles? What I’m talking about here is this button in the top-right corner. This is just one example. This visualization looks at my presentations. I used to love tracking this. I would travel all over North America and the world, in fact, to present at different Tableau user groups different strategies and tactics within Tableau. That all moved virtual, of course, a couple of years ago.
I continue to track some virtual events. So first thing you’ll see is that timeline. There’s three virtual trainings this year. And then this week, we’ve got, like I mentioned, our very first Playfair Plus webinar. But then those blue dots are places that I visited in the past. And there’s a toggle in the top-right corner that allows you to turn that on and off.
So if I click the button, it swaps out a different image. The button now appears to be off, and the past events have been wiped off the map. If I click the button again, then the toggle image changes, showing to the end user that you have turned on the past events, and then the map gets populated. So that’s just one use case of what we’re talking about today with toggles.
The first thing you need in order to create all of the following techniques are images for your toggles. So I’m going to show you three or explain three different ways to create those images or access or at least find those images. And the first way is you can make them. Can use PowerPoint. You can use Photoshop. A very popular tool right now that we have a couple of blog posts for on playfairdata.com is called Figma. We have a blog post called “The Definitive Guide to Buttons in Tableau,” which might be a good place for you to start.
But you can make them yourself. One tip if you do make them yourself, I encourage you to make the background of the button transparent and save the image with a file type of .png. That’s what allows the background to be transparent. And when the background is transparent, it allows you some additional flexibility because you can better integrate those images within the rest of your dashboard.
So you’ll have a picture– in fact, if I could go back to the Where’s Ryan visualization. Because the background is transparent, you see the button, and then the background color there is seamless. You don’t see a white square. That’s what I mean by having a transparent background.
But why reinvent the wheel when you can search for images? So that’s the second technique I’ll show you to creating your button images. You can simply search for them in Google. Again, because I recommend the image type be PNG, I recommend you search for either button PNG or toggle PNG because a lot of times, that will help you get to the correct file format for your buttons.
So I search for toggle PNG, and I’ll go to the Images tab within Google. We see quite a few options here, quite a few sets of toggles that could be used. This is the universe of everything that Google’s finding. But I wanted to show you that there’s a way to categorize these search results for different license types in order to use the images.
Most people and creators don’t just create something, spend their time working on an image, and put it out there on Google, and it’s just free. A lot of times, there’s a license that’s associated with using those images. If you ever have a question about that or you want to be fair to the creators, if you click on the Tools button within the search results page, the dropdown we’re looking for is called Usage Rights. And if I click on Usage Rights, you can see there, by default, as I mentioned, we’re looking at everything that Google could find.
But then there’s two different types of licenses. There’s a Creative Commons license. These are licenses that the creators have allowed you to use this royalty-free. They don’t expect any payment. They don’t expect any type of credit when you go to use the images. Those are fair game for you to use. The other one is Commercial and other licenses, and these often require some type of fee for you to download and use the image royalty-free after you pay for it.
So let me show you the difference between these because I think you’ll be a little disappointed in what is actually free. This is the Creative Commons results. You can see that we’re highly limited. I’m not sure if this would work for a toggle button in Tableau, and you can see there’s actually not very many at all on here.
If I change that to Commercial and other license, that’s where all those other results will come in. You’ll see some paid sites, like shutterstock.com. iStock Photo is another popular one that you might see here. These are usually pretty reasonable fees. I know iStock Photo is $12 per image. Once you pay that fee one time, you then have access to those images. You don’t have to worry about crediting the creator.
But better yet, one more place I’ll show you is probably my preferred place to create my toggle images, and that’s called thenounproject.com. Very similar to what I just mentioned with iStock, they do charge a small fee to download these and use them without crediting the creator, but that fee is $3 per image. A lot of times, you can find a complete set of buttons or toggles, so you’re technically getting two or three images for the price of one.
Just to show you some examples, if I search for toggle, this is the results page within The Noun Project. There are more than 2,400 different icons and/or sets of these button icons– quite a few good choices. Another thing that I like about The Noun Project is once you find an image that you like– I’m not logged in at the moment, but– oh, here we go.
It does still allow me to preview the image. So you can change the color of that icon to whatever color you want. Looks like they’ve got some defaults, but you could also put in custom hex values or RGB. Those are two different types of color codes which allow you to create these icons in the exact color that you want right out of the gate, right before you even download it. That way, you don’t have to do any post-customization after you download it. So you can customize it, download it.
Regardless of those three approaches to creating your toggles, once you have the images, you need to put those images into a folder on your computer called My Tableau Repository. So when you download and install Tableau, Tableau automatically added a folder within your Documents project called My Tableau Repository. So that will be on everybody’s screen if you’ve ever used Tableau before, everybody’s computer, rather.
If I double-click on My Tableau Repository, there are some additional folders in here. The one that I’m interested in is called Shapes. This Shapes folder is what maps to the shape palettes when you’re using a mark type of Shape. So over here in Tableau Desktop, I’ve changed the mark type on the marks card to Shape, which added a sixth property to the marks card. And if I click More shapes, these are the palettes that I’m referring to.
So anything that you put into your Shapes project within your Tableau Repository will show up as a palette over here on the Shape property of the marks card. In my Shapes folder, I have a folder called Toggles. So before the event began, I created these images, and I dropped them into this folder. We’ll be using all of these bird icons, this normalization button, and this crosstab versus visualization button. So I’ve placed all of those images into my Shapes Repository. Now those are available to me as a shape palette over here in Tableau Desktop.
Alright, for the first example– let me get this back to the defaults. For the first example, we’re going to create a toggle that I think will be very relevant, regardless of what business you’re in. This is a very important strategic technique when you’re analyzing data, and that’s to allow the user to toggle normalization on and off.
To show you an example of why this is needed, I’m going to make a quick map that looks at State, and then I’ll color those states by Sales. And if you’re in the US, you’ve likely seen this over and over again. Any time you’re using some kind of aggregate measure, typically, those the sum of that measure, the top states will always align with the states that have the highest population. So in the US, that’s California, Texas, New York, Florida. No matter what measure I put on here, if it was a sum of something like I have now with Sales, those are probably going to be the most popular– the most highly performing states, quote unquote, and it’s simply because they have the highest population to buy stuff.
So that’s not really delivering much value to my end users. What would be better is if I had the option to look at this as either SUM of Sales by state or Sales Per Capita, so sales divided by population. To create that. I’m going to show you under the hood a little bit on this data source that I’m using.
If you want to mostly follow along with these examples, I’m using the Sample Superstore data set. There’s just so many good teaching opportunities in there, so I like to use that. I have made one small tweak to the Sample Superstore data set. I’ve replaced the (Category) dimension that we’re– if you’ve used Tableau, you’re probably very familiar with that– with Brand. And I’ve just put in some fun kind of corporate branding in there that had the three different types of birds, Kingfisher, Meadowlark, and Hummingbird. That’s the only change I made there.
But for this example, I’ve also joined in a data set that looks at population by state. So in an Excel file– this is the whole data set. It only has two columns. And the first column is a dimension called State, and the second column is a measure called Population. I added a second connection, Population by State. I dragged that table into this view, and Tableau– this is called a noodle.
This was released a few versions ago. But Tableau is now using what’s called the logical layer to automatically join Orders and Population by State on the State dimension. Previously, if your Tableau is very out of date, you will not see the noodle. You’ll see what’s called the physical layer. That’s kind of your traditional left join.
You could do the same exact thing. But in the past, there was some extra steps you had to take to dedupe the data. And in fact, we have a blog post on that too. At the end, you could look that up. It’s “How to Deduplicate Joined Rows in Tableau” I believe is the title, but we’ll share that in the chat.
But we’re good to go. Now that that has joined, and I have– essentially, I’ve bolted on, is how I think about this, an extra metric for Population. That will be available to me in my data set, and I can make a calculation that computes sales per capita. And the formula for that would be SUM of Sales divided by SUM of Population. I’ll just blow that up so you can take a look at it. So that’s going to get me sales per capita.
If I were to drop that onto the Color property of the marks card to replace SUM of Sales, you’ll see a very different result. Actually, before I do that, take note of the color legend here in the top-right corner. It currently goes from $920 to $457,688.
If I replace SUM of Sales with Sales Per Capita, you’ve already seen the color of the map change quite dramatically, and our range is much, much smaller because we’re taking those sales amounts, and we’re dividing them by populations that can often be in the millions of people per state. And so now we’re looking at $0.00065 to $0.03057.
So that’s helped my analysis. But what would be even better is if we could have a button that just allows the user to flip back and forth between those two things. The first step we need to do that is a parameter. I like to create a parameter by either right-clicking in any blank space in the Data pane, or if you click this down arrow in the top-right corner of the Data pane, the second option will allow you to create a parameter.
I always start my parameters with the syntax p-dot. That just reminds me when I’m going later on to type a calculated field which of my fields are parameters. So p. and I’ll just call this Toggle.
Parameters must be assigned a data type. For this example, we will use a data type of Boolean because there’s only going to be two options, either True or False. That’s what the Boolean data type does. So I’ve changed the data type, and that actually is the entire parameter, so that step is done. I’ll click OK.
The beauty of this first technique is I can now integrate that parameter with as many fields as I want. I’m just going to do this with one field that allows us to flip back and forth between Sales and Sales Per Capita, but you could do this throughout an entire workbook with every single measure if you wanted to. I’m just showing you the basic example, but that’s one of the big benefits of this first technique.
And by the way, I call this first technique just how to add a Boolean toggle switch. This is the most common use. I’d say it’s kind of mid-range, kind of intermediate on how advanced this technique is.
So second step, I’ll create a calculated field. And I’ll call this Sales or Sales Per Capita. And whenever I’m writing a calculated field that has just two outcomes, I like to use what’s called the Immediate IF statement, which starts with the syntax IIF, open parenthesis.
And what comes next is my logic statement. So in this case, I’m going to say if p.Toggle=True, which means it’s turned on, I want to show Sales Per Capita. Otherwise, I just want to show SUM(Sales). So that is the entire formula there.
Whenever you’re writing a calculated field, if you ever see something blue that you haven’t used before, you can click on it. And Tableau will open it up over here on the right side in this little data and function dictionary. And that’ll show you what that function’s going to do, but also how to use it within the syntax.
So just to reiterate what I’ve done so far, I’ve used the Immediate IF statement. What comes first is my logic. I’m just saying if the toggle is on, then whatever I type after the first comma is the result when this statement is true. So when that is true, I’m going to show Sales Per Capita. Whatever comes– whatever I type after the second comma would be the result when this statement is false.
So in this case, when the toggle is turned off, I’m just going to show the default SUM of Sales. Says my calculation is valid. To test this out, I’m going to replace Sales Per Capita on color with my newly created Sales and Sales Per Capita formula. So I’ll drop that on there. I didn’t see anything change, which is good. Because if I show the parameter, we can see that it is turned on, meaning that it should be showing Sales Per Capita.
So in other words, I just essentially replaced Sales Per Capita with Sales Per Capita. But now if I change this to False, the normalization has been turned off. And I’m back to the default SUM of Sales. So that’s– again, we’re adding more value to this analysis that’s already getting better. But instead of having this kind of clunky parameter selector here that says True or False, we’re going to convert that to a button.
But before I show you how to do that, I’m going to save this first view as a map. And maybe I’ll make one more view. And actually, while I’m in here– never, never love the default colors. So maybe I’ll clean up the map a little bit, just put it kind of more in brand. Nice green color.
Maybe add a border with the same color to give that a nice clean look. I also– I think that the background images are a little bit busy, not really adding value to my analysis. If I’m a business in the US, I don’t necessarily need to know all these different cities in Mexico. So to turn those off, I could navigate to Map, Background Layers, and just wash out the entire background. Just gives it a nice clean look.
And then maybe I’ll add one more sheet. And we’ll call this Sales, Sales Per Capita Bar Chart. And I’ll just double-click on Sales. Nope. Double-clicked on the wrong one. Sales or Sales Per Capita is what I’m looking for. And I’ll break that down by State.
With this chart type, I usually like them to be going left to right horizontally. So I just swapped the Columns and Rows axes. And then lastly, I want to sort my states by that field. In descending order, Sales and Sales Per Capita.
Last thing, maybe I’ll add a top 10 filter. So I’ll drag State onto the Filters shelf, navigate to the Top tab, and change that to show me just top 10 by Sales Per Capita. Always like to QA everything. That’s one of my biggest tips for you, no matter what you’re doing in Tableau.
So I’ll show my parameter right now. The normalization is turned off, so we’re looking at SUM of Sales. If I turn that back on, we should see a different top 10 and different axis range, because now the data is being normalized. SUM of Sales is being divided by Population. So looking good there, other than maybe I’ll make the color match the other view and make this fit the entire view.
All right. Maybe I’m getting distracted cleaning this up a little bit. So I’ve got the two views. Next up, let’s make the button that actually turns this on and off for us. Gives our users a very nice experience. So I’ll add a new sheet, call this Button.
The formula that makes this whole thing go, so it’s a calculated field. And I’ll call this my Boolean Button, is the function IIF again. And we’re going to say that if p.toggle=False, then use the True value. Otherwise, use the False value. I’m going to show you why this is important in a minute, but that is the formula. And that is going to be used to create the button shapes.
So that’s the whole formula there. I’ll click OK. And I’m going to change my mark type from Automatic to Shape. And that Boolean Button is what I want to place onto the Shape property of the Marks card. So when I do that, we should see something appear, says False.
Make this a little bit bigger. I will also show the parameter to show you that it’s currently set to True. So that was a quick QA that’s showing me my logic is working. If the toggle equals False, it’s going to show True. So if the toggle equals True, it’s going to show False.
This logic is a little tricky to wrap your head around, but even though the button shape says False, we want to map an image that appears to make it look like it is True. Because right now, the parameter is set to True. So I’m going to, in other words, map my on shape to that False result there.
To map new shapes, you can either click the shape property or double-click on the shape legend here. Navigate to that palette that we installed to kick off the webinar. And the toggle that I’ll use this time, it’s hard to see in the resolution of these, but this button, it’s a rounded button that says Normalize. And when it’s True, it’s kind of lit up. It’s in full color. So that’s the option that I will choose for False.
You can always preview a change by clicking the Apply button. That’s pretty small, so I still can’t see it. So I’ll go ahead and click OK and make this whole sheet a little bit bigger, just to make sure we can see this. That looks like a pretty good size there.
Also, I always like to turn off the tooltips of these. You could do some type of call to action, like “Turn normalization on or off”. But I’ll just turn that off, thinking that the image of the button implies what’s going to happen. So I’ll click OK. So we’ve got the True shape match– mapped.
Now if I change the toggle to False, we’re back to the default shapes. But notice it’s now passing the value of True as the result. So I’ll double-click on that and map my False shape this time. So again, the logic is a little backwards. Even though the result is True, the parameter is currently set to False.
So I want to map the kind of grayed out looking version of that Normalize button so it looks like it’s turned off. I’ll click OK. We’ve got the whole button now.
That was everything that we needed. Now I’m going to create a dashboard and kind of tie all this together. So I’m going to place the map onto the view as kind of my base layer. I don’t need these legends and the toggle dropdown, because we’re going to hook up this button. So that’s no longer needed. So I will just get rid of that entire container.
Maybe I’ll float my top 10 kind of down here in the bottom right corner of the view. Just kind of format that a little bit. And then lastly, my button. I’ll float that kind of in the top left corner of the view.
Don’t need these legends. I’ll maybe fit the entire view, resize that a little bit. And we’ll call that good. So there’s my dashboard. I don’t think I need this title. Bump that up a little bit. Alright.
Last thing is we need to hook that button up, so that it actually does something. Right now, I’ve got a nice image on there, but it’s not doing what we think it should be doing. To finalize this technique, we’re going to use a parameter dashboard action, which you can add by clicking Dashboard in the top navigation and choosing Actions.
And I will add an action. There are six different types of dashboard actions. We have a video here at Playfair Plus that shows you an introduction to dashboard actions. But for today’s techniques, we’re going to use the Change Parameter dashboard action.
I’ll call this my Boolean Toggle again. And this is pretty intuitive. It’s asking me what’s the source of the action, which is the Button itself. I want it to run when I click or Select that sheet. We are targeting the p. Toggle parameter.
And we are passing the Boolean Button. That’s why that logic was so important. Because when the normalization is turned off, or appears to be turned off as it is now in the button, the value inside that button is actually True. So when we pass the Boolean Button value, it’s going to pass True to the p. Toggle parameter. It’s going to turn the normalization on, and it’s going to flip which image is being shown.
Sounds like a mouthful, but it actually works pretty well if you follow along with the steps. We’ll also, of course, share a blog post, and you can watch the recording if you need us to slow down at all. But that is the entire parameter. I’ll click OK. Click OK again.
We’ll go to Presentation mode to see how we did here. And this time, if I click the Normalize button, you saw the color shift. You saw the top 10 shift. You also saw the button light up, showing me that I’m now looking at the on switch. If I click that again, it goes the other direction, passes the False value, turns the normalization back off, and then it swaps in the grayed out image.
There’s one big thing that I don’t like about this, and that is when I click an image like this, by default Tableau is adding a background. Actually, I’m sorry. It’s selecting it which is requiring me to click twice. I have to deselect it and then click on it again to get it to activate.
Well, I have discovered a really nice trick for that. It’s very easy. If you add a second dashboard action– so I’ll add Action, choose Filter this time, and call this Don’t Select. And I want it to run on the Button sheet again when I click or Select it.
But here’s the trick. If I simply change the Target Sheet to the Button sheet itself and make sure that the clearing the selection is set to Show All Values, this kind of fakes Tableau out. And it automatically deselects the button for us. So let me show you what I mean by that.
If I click OK, click OK again, go back to Presentation mode, this time when I click Normalize, notice that background is going away and it’s already deselected. So with a single click this time, I’m able to toggle normalization on and off. So that was technique number one.
But before we get too carried away, I want to– I promised that I’d provide techniques for all skill levels. I’m going to show you the easiest way possible to make a toggle. And the use case that I’m going to use this time that I think, again, you’ll get a lot of use out of your business is we’re going to set up a dashboard that allows our user to toggle between data visualizations and raw data. Even the best of us, 12 plus years into this now, we still get requests to just give me the raw data.
So this technique I’m about to show you is kind of a gateway that helps those end users that are comfortable seeing the raw data at least gives them the choice where they can sneak in data visualizations, because you’ll have a nice little button there to kind of visualize the data. If they just absolutely need the raw data, they click the button again. Voila. They’re given the detailed data on demand. So that’s what I’m going to show you how to do next.
For this one, first let’s set up a table. So I’ll just call this my Crosstab. And I’ll this time pull in– let’s see– Sales Per Capita, Sales, and Population. So I’ll click on those three. Go over here to Show Me.
We wanted to break that down by state, didn’t we? And so let me put State on there, swap my axes. And here is our big ugly table. I know some people need it, so I’m going to keep going with it.
Let’s see. I’m going to at least add some decimals to Sales Per Capita. So there we go. We’ve got a crosstab of data. I’m going to start a new dashboard. And I’m actually going to add that sheet as kind of the base layer.
Whenever I’m doing this technique, I’ll use a floating object. That way I can customize exactly where it is on the dashboard, its exact dimensions. So I’ve placed the crosstab on the view. Now if I go to Layout– let’s see.
My dashboard is 1,000 wide. So maybe I’ll make this 800 wide by 600 tall. Kind of center it on this default dashboard. 100 in on the x-axis, 100 down on the y-axis. We’ll call that close enough. So there’s my crosstab view.
Next up, and what makes this technique go, is the next object that I’m going to add to the dashboard is going to be a layout container. Let’s say– I’ll keep going with the first example, and I’ll put a kind of rudimentary view or dashboard that has both the map and the bar chart side by side. So because they’re going to be side by side, I will add a horizontal layout container to the view.
The first trick with this is you need to lay it exactly on top of the base layer. So I’ve got the layout container on the view, but I’m going to go to the Layout pane and give it the exact same position, in on the x-axis and down on the y-axis. And I’m going to make it 6– it was 800 pixels wide by 600 pixels tall.
Also very important with this technique, you’ll want to give the background a solid color that matches the rest of the dashboard. So in this case, by default, that’s simply white. That way I can no longer see the underlying cross tab for now.
Now I’ll go ahead and create my dashboard. I had a map in there. And by the way, to get a object into a layout container, you drag it close to the container and hold the Shift key. Then let go. And it places it in the container.
I’ll do the same thing with my top 10 here. Drag that in. Maybe format this just a little bit. The map should probably be a little wider than the bar chart. We’ll call that good.
It’s not necessarily meant to be perfect at the moment. Just showing you capabilities here. But because this is inside of a layout container, layout containers have a special option to show or hide those containers with an image of a button. So to do that, I’ve selected the entire container. Click the down arrow that appears in the top right corner of the container. And choose Add Show/Hide button.
By default, it just looks like an x when it’s turned on. But you can edit that button and change not only what image is being shown, but the tooltip, which is a nice little touch that allows us to add a call to action. So when the item is shown, I want to choose an image that looks like a crosstab, which will imply that if the user clicks on that crosstab icon, it’s going to close the container and the base layer, which is when the cross tab will appear.
So I’ll click Choose. I’ll choose that crosstab button image. Also when it’s being shown, I can maybe add a call to action to the tooltip, such as “view the raw data”. Then I can navigate to what I want to display when the container is hidden or turned off. So in this case, the map and the bar chart have gone away, and I’m looking at the crosstab.
So for this version of it, I want to show the icon that looks like a visualization, implying that if you click it, the data will be visualized. And maybe for the tooltip this time, I’ll say “visualize data”. I’ll click OK.
Another nice thing about these Show/Hide buttons is this essentially just became its own floating image. So I could position this wherever I’d like. I can navigate to the Layout pane, maybe bump up the size of the image button if I– or button image if I’d like to. All kinds of flexibility there. But that is the entire technique.
If I go to Presentation mode, when the layout container is being shown, I see an image of a crosstab. And if I hover over it, it says view the raw data. When I click that image, the container disappears, revealing the base layer, which is the raw data. The image was also replaced with the visualization. Now if I hover over the visualization icon, it says visualize data.
And I can go back and forth with the click of a button. I even like the little subtle effect of hovering over the image and it kind of grays out, showing you that something is activated or might happen when you click on it. That, by the way, was the exact same technique used in the Where’s Ryan viz.
So I had a base layer that didn’t show anything. If I turn the button on, that’s just turning on the container. The Show/Hide button activates the container, and all the events are populated. That’s what I used there. So that I would consider the kind of fundamental version of toggles.
Lastly, we’ll cover the advanced version of the toggles. And I’ll show you how to use a toggle even when you’ve got more than two options. This is a technique that I call button swapping. We wrote about it a couple of times on the Playfair Plus platform.
You can use either sets or parameters with this. The difference would be if you only want to choose one option at a time, like we’re doing with these toggles today, I would recommend that you use parameters. So that’s what we’re going to do today.
Let me set up another quick chart that looks at sales by region and month, just to give us something to take a look at and make sure that this is working. So I’ve got SUM of Sales and Region, and I’m going to break that down by continuous month. I may change my mark type to Bar. Alright.
As I mentioned to open, I did replace the Category column in the Sample – Superstore data set with my own dimension called Brand. It has three different dimension members. Instead of Furniture, Office Supplies, and Technology, it has Kingfisher, Hummingbird, and Meadowlark. Those are the birds that happen to be on the covers of my three books on Tableau.
So I’ve got Brand. I’ll go ahead and color the bars by brand. Maybe map something that’s a little bit more aligned with each one of these. So Hummingbirds, green. Kingfishers, red. Meadowlark is yellow.
Alright. So this is a technique that I like to use a lot before I get to the toggle. If I ever want to filter to one of those dimension members, instead of using the traditional filter by just dragging Brand to Filters, you can make your filters kind of more scalable and even have them perform a little bit faster. So in other words, making the dashboard kind of respond and process as efficiently as possible if you set these up as Boolean formulas.
So I do this a lot. I just set up a filter that says Brand = — Oh, I left out of step. Back up a second. First, we need a parameter. We made the p. Toggle, but we need to make a parameter for p. Brand. So the easiest way to do that is to right click directly on the dimension that I want to create the parameter from, hover over Create, and choose Parameter.
That’ll save you a few keystrokes in Tableau, because what’s nice about how I just created that parameter is it does two big things for us. The parameter is automatically set to the same data type. So Brand is a data type of String, therefore my newly created parameter also has a data type of string.
It also automatically populated the list of allowable values with the dimension members from that Brand dimension. So I’ve got everything I need here. Only step left for me, if I like to follow this syntax, is to give it a better title. I’ll call it p. Brand.
Alright. Now I can create that Boolean filter that I was alluding to. I’ll create a new calculated field. Call this Brand = p. Brand. And that actually is the entire formula. So I’ll just type that again.
This is a Boolean formula. So the result– In fact, if I go ahead and click OK, you’ll see that the data type has an icon next to it. It says T|F, telling me that’s a Boolean. And that means there’s two outcomes that’s either True or False. So if I were to place that onto the Filters shelf and choose True, it’s only going to keep whatever the current value of the parameter is.
So if I click OK, I’m left with just Hummingbird. I could QA this by showing the parameter. And sure enough, Hummingbird is the current value of the parameter. If I change that to Kingfisher, the view changes to Kingfisher. Change it to Meadowlark, the view changes to Meadowlark. Get back to Kingfisher here.
Alright. So now we’ve got something. We’ve got a visualization. We’ve also got a filter that’s going to keep only the current value of that p. Brand parameter, allowing me to see one brand at a time. Now we’re going to make a really nice user experience and make a button selector that swaps in different images depending on what you have selected.
Let me give this a name, too. I’ll call this my Sales by Brand Trend. I’m going to start a new sheet. I’ll call this my Selector. And for this one, we want to change the mark type to Shape and add Brand, or whatever I’m eventually going to allow my user to select from, to the Columns shelf. So now we’ve got three different columns that we can map.
I do like to change the sort order of these to go in the order that my books were released in. So I’ll put Kingfisher, which was on the cover of Practical Tableau, first. Hummingbird was on Innovative Tableau, and Meadowlark was on Tableau Desktop Pocket Reference. So put those in the right order.
Now I’m going to make the formula that really makes this whole thing go. I’m going to start a calculated field. And I will call this my Button Shape. And the formula is my Brand = p. Brand formula. So remember what that’s going to do. The result’s going to be one letter, either a lowercase t or a lowercase false, indicating that’s either true or false.
I’m then going to concatenate that t or f to the Brand dimension. It’s giving me an error message, and that is because p = p. Brand is a data type of Boolean. Brand is a data type of String. There’s an easy solution to that. Simply wrap Brand = p. Brand, which is currently a Boolean data type, with the function STR, which will convert it to a string.
So now I’m adding a string to a string. And there’s going to be six different results of this formula. For each of my three different brands, they can either be true or false. And eventually that’s going to mean they’re either selected or they’re not.
So two outcomes per my three brands. That equals six possibilities. That is the entire formula. I’ll click OK. I’m going to drag that to this Shape property. And now I can start mapping these different outcomes.
So look closely on the shape palette here. It says lowercase f Hummingbird, lowercase f Meadowlark, lowercase t Kingfisher. That’s telling me that Kingfisher is the current value of the p. Brand parameter. And sure enough, it is.
So now I want to go in here and map the different shapes. I’ll just double-click on the shape legend, navigate to my custom Toggles palette. When Hummingbird is not selected, I want to show this grayed out picture of a hummingbird. Same thing with Meadowlark. And then for the one that is selected, Kingfisher, I want to show a colored version of the image.
I can always click Apply to preview that. It looks pretty good. I’m going to temporarily close the mapping there to make a couple of changes. I’ll turn my tooltips off. Maybe make the size of those buttons a little bit bigger.
Turn off my header. Turn off all my lines. Right now, those are row dividers. So I’ve got this nice, clean selector. That is one of the outcomes. But as soon as I change this to something other than Kingfisher, I still have some work to do on my mapping.
So I changed it to Hummingbird. Now Hummingbird is selected, so I want to map the colored in hummingbird image. Kingfisher is now not selected, so I want to change that to the grayed out version of the (kingfisher). Apply that. Looks like so far, so good.
I need to close this temporarily to make the last selection, which is Meadowlark. And we should have just one more thing we haven’t mapped yet, which is true Meadowlark. So I’ll go in and map the colored in version of the meadowlark. Click Apply. And looks good.
So I’ve already kind of got this hooked up. Now if I choose a different brand, you’ll see that it’s swapping in the colored in version. So just to reiterate one more time what that’s doing, when I click Kingfisher, my Brand = p. Brand becomes true only for Kingfisher. So we see the t. and it concatenates the name of the brand.
The others are getting false, because the logic is not true for the other two. So they’re getting an f concatenated with their brand. And because we mapped the images, it’s always going to swap in the correct images.
We’re now ready to hook this up and put it on a dashboard together. So I’ve started a dashboard. I’ll change this back to tiled and put on my Sales by Brand Trend. Don’t need this right side so I’ll close that. I’ll put my Selector at the top.
Again, don’t need all this extra– these legends and things on the right. I’ll make this fit entire view. And we’ll call that good for this demonstration.
So these, we’ve got these working independently now, but we haven’t hooked anything up. So it’s– they’re kind of static right now. The images won’t change. It’s not passing any values. It’s not doing anything.
Much like example number one of the toggles, I’m going to leverage a parameter dashboard action. So I’m adding an action. We’re going to say this is the Brand Selector. And when you click on the selector, we’re going to target the p. Brand parameter.
And very important here, because you have two options this time, we want to pass the default Brand. We don’t want to pass the Button Shape, which is the letter plus the brand. We want to pass only the Brand. And that’s the entire parameter. So I’ll click OK. Click OK again.
And now if I go to Presentation mode, this should be hooked up. So if I click the hummingbird, the Hummingbird brand is passed to the p. Brand parameter. That value is then passed to my p. Brand = Brand calculated field, which filters my trend. It also changes my brand shape to t Hummingbird. That passes in and swaps in the selected image.
And the other two are now f Kingfisher and f Meadowlark. So quite a bit just happened there. If I click Meadowlark, it switches over to Meadowlark. We can see that’s all working.
Same issue with the other toggle, where it’s making me deselect things. And it’s got some extra– actually, let me double-check something real quick. I think this other logic might have been left in here. No.
I was going to say you usually have to do the same kind of trick with the filtering. This is actually decent, but you could use the same dashboard action as we did in the first example. And I’m going to add a second dashboard action to this dashboard that says if you click the selector, navigate to the selector sheet, and show all values.
Click OK. Click OK again. And now that’s the cleanest, cleanest user experience possible. It’s automatically deselecting the images that I’ve clicked on.
This has been Ryan with Playfair Plus – thanks for watching!