Ryan Sleeper
Move beyond Tableau’s default formatting and UX options by learning how to create custom menus. This user experience technique that we implement at Playfair Data unleashes infinite formatting options to increase the user engagement, interactivity, and adoption of your dashboards.
Calculated Field That Computes the Button Value: IIF( [p.Toggle] = False, True, False)
Hi, this is Ryan with Playfair Data TV. And in this video, I’m going to show you how to make custom menus in Tableau. These custom menus will essentially act like a custom Show/Hide button experience with one major difference. I’m going to show you an advanced user experience that allows you to automatically close the Show/Hide window after a selection has been made in the custom menu. By the end of this video, you’ll be able to make something similar to what you see on the screen here. Notice that when that button is clicked, a menu appears. And after the user has made a selection, not only is the view filtered to that selection, but more importantly, the Show/Hide container automatically closes. The first thing you need to create this user experience are some unique custom images. You can go about making these in several different ways. That’s beyond the scope of this video, but I will put a couple of sample images in the related content so that you can follow along and get some practice with this. The buttons that I will use will look just like this on the screen here, where when the menu is hidden, it will have a right arrow. And when the menu is being shown it will have a down arrow. Once you download your images, you will need to put them into a folder on your computer called “My Tableau Repository”. When you install Tableau, you’ll see a new folder within the documents project called “My Tableau Repository”. And within that folder, there’s a project called “Shapes”. This folder are all the different shape palettes that are available to you when you’re changing the Shape property of the Marks card. If I click into that folder, you might recognize some of these palettes, because several of these come out of the box, by default, with Tableau. But what you might not know is you can also put in custom palettes. So I’ve added a folder called “Buttons”. And within that folder, you’ll see my list hidden and list shown buttons. We will need those later on when we go to map these images. So that’s the first step. But assuming you have some custom images, we are ready to get started over here in Tableau Desktop using the Sample – Superstore data set. The first step is I need to create a Boolean parameter. I like to create parameters by right clicking in any blank space on the Data pane and choosing Create Parameter. I’ll call this my p.toggle That p dot is just my own naming convention to remind me what’s a parameter versus what’s a calculated field. The data type for this parameter is Boolean, because there’s only going to be two outcomes, true or false, which will tell Tableau whether the button should be in a shown or hidden state. But that is the entire parameter, so I’ll go ahead and click OK. And the second step is really the formula that makes this whole thing go. I’m going to create a calculated field. And I’ll call this my button value. And I’ll share this in the related content below the video as well, but the entire formula for this very important field is the immediate IF function followed by an open parentheses. Then, we’re going to reference that p.toggle parameter that we created in the first step. Equals False comma True comma False. This is my preferred technique for creating a Boolean toggle in Tableau. I’ve shown you how to do this on another video, where you simply click a button to toggle things on and off. It’s also going to work with this user experience, because we’re essentially swapping out that list shown and list hidden– those two different images. So you’ll need that formula. The logic’s a little bit backwards. But what we’re saying is, when this parameter equals false, then the value will be true. Otherwise the value equals false. The reason we have that backwards logic is in one of our last steps we’re going to code a parameter action that passes that value, and I want to pass the opposite value, so that it toggles back and forth. I will go ahead and click OK to close that calculated field. The Mark type to map this out will be Shape. So I’ll change the Mark type to Shape, and put my newly created button value calculated field onto the Shape property of the Marks card. And just to keep our logic a little bit straight, I will go ahead and show this parameter. Because notice it says false for the button value right now. But if I show the parameter, the current value is actually true. So when we go to map our images, we want to map the opposite image. If the button value is false that means the parameter value is true. So I want to map an image for when that list of options is being shown. To do so, I just double clicked on a dimension member from within my Shape palette. And here’s the dropdown I was referring to earlier, when I said that the Shapes project within your Tableau Repository is associated with these palettes. Because I put in my own folder, there’s one called buttons. And these are a little bit hard to see but I can kind of see that that second image is the down arrow, which is what I want to show when this equals true. So I’ll click the dimension member. Map the down arrow. Click OK. And that’s way too small. So let me– and I’ll also turn off my tooltips. And let me make that a little bit bigger. Maybe bump up the size of that mark just so we can see that a little bit better. So sure enough, it is my button with the down arrow. To map the other state, I’ll change my p.toggle value to false. And now I can double click into that Shape legend, choose my Buttons palette, and it will be the first image this time. And click OK. All right so the button is now intact. That’s the very first piece of this. To activate that button and allow my user to interact with it, and switch it from a selected versus non selected state, I need to add it to a dashboard. So I’m going to go back to a dashboard. I’ve called this “Custom Menu”. I’ll make this Floating and drag my button onto the view. Let me hide some of this. I don’t need the Shape legend. I will maybe leave this parameter up there in the top right corner. Just so we can make sure that that’s working. And let me do a couple more things here. I’ll fit the Entire View. Just kind of format this a little bit. And we’ll call that good. So we’ve got nothing but a button on this dashboard, so far. To activate that button, just like with a Boolean toggle, I’m going to navigate to Dashboard, and Actions, and add a Parameter Action, which you can do by clicking add action and Change Parameter. I’ll call this my “Button Toggle”. And we only have one sheet so far, so button is the correct selection. I want it to run on click, or select. We will target the only parameter we’ve set up so far, p.toggle and we will pass the button value. So that is all of the settings for that very first Parameter Action. I’ll go ahead and click OK. Click OK again to close this. And let’s make sure this is working. I’m going to go to presentation mode. And now, when I click the button, notice that the image gets changed to that down arrow. I need to click it to de-select it. We’ll address that in a moment. I have a trick to get around that. But I’ve de-selected it. Now if I click it again, it should go back to the true value. De-select it, and click it again, now it’s passed that false value, which makes the toggle true, and we see the down arrow. Can de-select that one more time. So the foundation of that user experience is intact. Now we need something to toggle on and off. And in this case, I’m going to allow the user to toggle a Region selector. This can be made with any dimension, for any purpose, or any filtering. But for the purposes of this example, we’ll use the Region dimension in the Sample – Superstore dataset. To do so, I will need another sheet, which I’ll call “Selector”. And this one needs a second parameter, because we’re eventually going to let the user pass the value in the selector to the parameter, to filter the marks on the view. So just to get prepared for that, and get ahead of that a little bit, I’ll go ahead and make a parameter that includes the dimension members from the Region dimension. Little shortcut to do that. I can just right click on the dimension that I want to create the parameter from, hover over Create, and choose Parameter. That’s a little shortcut, because it automatically populates the allowable values with the dimension members from that associated dimension. It also ensures that I’ve got the correct data type for that parameter, right out of the gate, without having to set that up. And in fact, that name is even good enough for me. So we’ll call that good. I’ll click OK. We’ll need that in a future step. For the selector, I’m going to keep this very basic for now and just make a simple cross tab view. You could even take this Selector sheet a step further and maybe make it highlight the selection. We have a video here that shows you how to do that as well. You could color things. You could have different shapes. But to keep it simple, I’m just going to drag the Region dimension onto the Rows shelf, and also drag that onto the Text property of the Marks card. That’s repetitive. I no longer need the original header. So I’ll right click on the Region dimension and deselect Show Header. And we’ve just got a very simple selector sheet. I also like to turn off the Tooltips so that those do not distract from the view. So here is how to connect this selector sheet with the button that we created in the first step. We need to create a calculated field out of p.toggle. And in fact, that’s the entire formula. That’s what’s going to make our parameter filter. To do that, I can just right click directly on p.toggle, hover over Create, and choose Calculated Field. Once I choose that, that again is the entire formula. I just will call this my “p.toggle filter”. And I’ll click OK. And to remind you what the current value of that parameter is, I will show the parameter. And we see that it is true. The reason that I made a filter out of that parameter is I only want this selector sheet to appear when p.toggle equals true. Otherwise, I just want it to disappear. So if the toggle equals false, I want this menu to disappear. So with that being set to true, when I drag p.toggle filter to the Filters shelf, we should only see one result. And we do. It’s true. But that is a very important step. It seems simple, but you need to make sure that your parameter value is set to true, so that when you go to add this filter, you only see the True checkbox appear. If I check that box and click OK, we won’t see anything change immediately. But if I were to change this back to false, we see the sheet disappear, which is exactly what I want. So when it’s being shown, we want to show the sheet. When false is in there, we want it to disappear. This Selector sheet also needs that button value, because we will also pass that true or false value to p.toggle. And maybe you’re starting to put this together but that’s what makes that sheet turn on and off. So one last step on the Selector sheet. I simply need to add Button Value to the Detail property of the Marks card. Again, we shouldn’t see anything change, but now that value will be available to me when I add it to a dashboard and try to set up a parameter dashboard action. Let’s add this piece to the view by navigating back to my dashboard. And the trick with getting this to appear on and off, and so that you can even use multiple selectors in a single view, if you’d like, is we’re going to add this within a horizontal or vertical layout container. For this example, we’re only going to have a single example. So it doesn’t matter which of those two versions I choose. I’ll just choose Vertical. And I’ll add that to the view below my button. And I will place my newly created selector sheet inside of that layout container by dragging it onto the view, and holding down the Shift key, and letting go. I’ll clean this up a little bit by hiding the title. Maybe make this fit Entire View. And I want to ensure that that Selector sheet is part of my very first dashboard action, which passes the button value. It looks like it came over by default. So notice, as soon as I added that selector, because selector also had that button value field on it, it is selected. So we should be good to go. I’ll just do some quick quality assurance as I go here. And remember, when I click a region, because that is set up within my dashboard actions, it should pass the button value and turn that button back off. And notice I now have a right arrow. If I click on that button, not only does the image get swapped out, but I pass the value back, again. Now, this p.toggle value is true, which makes that sheet appear. If I choose a different region, it should pass the value of false to this parameter, which swaps out this button once again. If I click South, sure enough, that is turned off. One nice touch that we could add to this so that it’s more apparent to my user what has been selected, is I could add a label directly to this button. There’s a couple ways to do that. We could add a separate sheet. But to make this as elegant as possible, and reduce our number of sheets, I’m going to go back to our Button sheet and add a filter for Region. This is where that Region parameter that we set up on the selector sheet comes into play, or starts to come into play. I’m going to filter this button so that it only includes the value that equals this parameter. Let’s show that parameter and see what it currently is. It’s currently Central. To make that button only contain a single value, I can add the Region dimension to the Filters shelf, navigate to the Condition tab, and type in a very simple formula, which is Region, from my data set, equals the Region parameter. And that will make sure that only one value is kept on the view. I’ll click OK. We don’t see anything change, but now if I add Region to Label, we should just see one region appear. And we do. It’s the Central region. From there, I can clean that up a little bit. Maybe center it. Maybe make the color white. You could obviously take this a step further and do whatever you’d like with the formatting there. But the point is, we now can see right there on the button what has been selected. Now, if I go back to my dashboard and add one more dashboard action which passes the value in my selector to the Region parameter, not only will this turn the selector on and off, not only will it swap my button from the selected state to the unselected state, and vise versa, but it will also pass the Region value to that parameter. And we’ll see the label update. So this is an advanced video. There’s quite a few steps to it. But I think this is a very nice user experience that isn’t taking too long to set up. And you can repurpose a lot of these steps, by the way. But I’m just adding a second parameter action. I’ll call this my “Region Selection”. This one I want to run on the Selector sheet. And I’m targeting the Region parameter. And I’m passing the value of the Region dimension. I’ll click OK. Click OK again. And let’s see how we did here. So clicking the Central button shows the sheet. Now, if I click a different region, there’s two things that will be passed when I click on East. It will pass the value of false to this toggle. It will also pass the value of East to the Region parameter. So if I click East– so the sheet closes. The button has been changed to its unselected state and the label has been updated. If I click the button again, we see the dropdown appear. Now, if I click West, the same thing. So very nice user experience. One thing that’s driving me a little bit crazy is, you saw that kind of fade– the label faded in. That has to do with the default animations in Tableau. We can turn that off by selecting the sheet, navigating to Format, and choosing Animations. And I could just turn off the animations, just for that sheet. I kind of like the default animation on the selector sheet because it, kind of, rolls in and animates in. So I’ll leave it on that sheet. But for the selector, I want the label to appear automatically so it looks seamless and not fading in and out. So I’ve turned off the animation just for that sheet. Let’s take one more look to see how we did. So I click West. Click the down arrow, or click the button rather, it turns into a down arrow. Now if I click the Central region, it closes it. And see, there was no fade that time. It automatically shows Central. Click the button, again. Click South. And you can see that that’s working. There’s one subtle thing that I’m still not loving about that button. You might notice that sometimes when I click it, it gets a black border around it. That’s partly due to this being a PNG file type with a transparent background. That is best practice to use. It gives us a little bit of flexibility in how we integrate those custom images within the dashboard. But I’m not loving that black border. I do have a trick for that, which is to add another Dashboard Action. This time, I will use a Filter Dashboard Action. And the trick is, I choose the Source Sheet, but for the Target Sheet, I change it to its actual sheet within the workbook, not within the dashboard. So to do that, under the Target Sheet options, I will change the dropdown from the dashboard that we’re currently on to Button. And if I have that run on Select– and then, this is the most important step. You have to show all values. If I click Show All Values, after closing this, we shouldn’t see that button being selected. So I click South, there’s no black border. I can click a different region, it closes. You never see that black border. Choose West, no black border. So this is turning out to be really nice. That is the foundation of this custom user experience. Now we can link that Region parameter to any sheet. So just to make a quick example, I will make a bar chart that looks at, let’s say, Sales by Region and Sub-Category. And I’m only putting region on there to ensure that it’s working still. So I’ll put Region on the view. I’ll also break that down by the Sub-Category dimension. And we said Sales was our measure, so I’ll drag Sales onto Columns. Maybe sort this in descending order. Maybe turn the color of the marks red, just to get it to match the rest of the view. I’m going to reuse that Region filter, like we did on the label for my custom button, by dragging Region to the Filters shelf, navigating to Condition, and typing in that same Boolean formula– Region equals my Region parameter. And that should keep only whatever the current value of the Region parameter is on the view. If I click OK, I can see that it is Central. Now, if I go add that sheet to my view– maybe I’ll line it up here, kind of at the top. Make this a little bit wider, taller. And then an important step here– we want to make sure this sheet is on the very bottom layer, because we don’t want it to overlap our container that has our selector. That’s kind of the sneaky thing about this technique. That container that is eventually housing our selector sheet is always on the view. It’s always in the same place. So we want to make sure that’s on top. To make sure that’s on top, I’ll click my bar chart sheet, click this down arrow, hover over Floating Order, and send it to the very back. Looks like it’s a little bit low– a little bit high, rather. So I’ll bump that down just so we can always see the headers there. All right and lastly, we no longer need this, either. And lastly, just to test this out, make sure it’s working, talk you through this whole user experience– right now, we’ve got central selected. That’s apparent by looking at the label on the button. It’s in its unselected state, so it has a right arrow. If I click the button once, we see a dropdown containing my four different region options. If I click on a different Region dimension, not only will that Region dimension be passed to the Region parameter, which will filter the bar chart, but it will also pass the false value back to my p.toggle parameter, which will close that selector sheet. It will also swap out the image back to its unselected state and change the label back to East. This has been Ryan with Playfair Data TV. Thanks for watching.