Creating a Custom State Selector

Create a parameter-based calculated field called "State Focus" that filters data to a selected state or all states by comparing the parameter value to the State field and including an "All" option for global filtering.

Create a dynamic state filtering control in Tableau using a calculated field and parameter for a more customizable user experience across multiple worksheets. Learn how to add an "All States" option to ensure broader navigation and how to troubleshoot common issues like conflicting filters and zoom settings.

Key Insights

  • Creating a calculated field called "State Focus" tied to a parameter allows users to filter data by specific states while maintaining consistent functionality across Tableau worksheets.
  • Adding an "All States" option to the parameter and updating the calculated field logic enables users to switch between individual states and viewing data for all states, improving dashboard flexibility.
  • Noble Desktop explains that using parameters (like the state selector) offers a global filtering method, avoiding the need to recreate filters on each sheet, whereas traditional filters are local and must be set up individually.

Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.

I'm going to assign this to a calculated field. So, I need to create a calculated field. This calculated field is going to be called State Focus.

So, I'm going to go to State Selector. I'm going to choose Create, and I'm going to choose Calculated Field. So, I can create a calculated field directly from the State Selector.

I could also create a calculated field up here and just click Create Calculated Field. But if I do it from the State Selector, it's automatically going to include the State Selector in the calculated field. And there it is.

I'm going to call this State Focus. I know we have all these names. And I'm going to say the State Selector is equal to State.

And that's what we're going to do. So, I think that's all I need to do. I'll click OK.

Now, I call this State Selector. In the instructions, it was State Parameter, but same difference. I'm saying it has to be equal to the State.

I'm going to click OK. And now it's over here. There's like a true false thing here.

Now, for this to work, I need to actually move it over into the filter. Because what's the point of doing that without having it filter the states? So, I'm going to drag this over and bring it into the filters. And I'm going to say, when it's true, when the State Selector is equal to the State, filter the State.

So, I'm going to drag State Focus over into filters. This comes up, and it's like a true false statement. I'm going to click here on true.

And I'm going to click OK. And it's already starting to work. So, now it's in New Mexico.

I want to get this to show. So, I need to bring up the controls where I can change this. Right now, I can't change anything.

So, I'm going to go to the State Selector. I'll click the drop down here. And I want to show the parameter.

For some reason, I thought it was going to default to New York. It didn't seem to do that. But let me now choose New York.

And now I see New York. I'll click here. Minnesota.

I see Minnesota and their sales. So, now I've created a custom control. If I put this into my dashboard, when someone sees this as a dashboard, they could use this to navigate to any individual state and see the sales for each state.

Okay. I'll press Escape. And I'm going to call this State Selector.

This is ready for me to add to my dashboard whenever I'm ready. One of the reasons this might not work is if you fuss around with the zoom controls. If I, let's say, zoom out a little bit, I've sort of like canceled out my ability to use the State Selector.

This has happened to me before in class. And sometimes it could take you a while before you figure out what's going on and why it's not working. If I click the drop down here and choose another state.

Hey, Garfield, I created it exactly like you said, but it's not moving. This has happened to me in class. It's been embarrassing when I couldn't figure this out.

And then you figure stuff out and then you don't do it again because you remember when it happened and say, I'm never going to do that again. And so I need to cancel out of this zoom level and then just reset the map. Now, if I go back here and then use the State Selector, it now works.

So that was one of the issues where I had trouble with this. Also, if you have other filters in that filter section, that can also affect because the filters will be fighting with each other. There are certain no-nos when it comes to using multiple filters.

Let me see, what is different from using a filter? So at least for this, you're jumping specifically to the area. And let's see. Let's actually take a look at that.

What's different from using a filter? I think the behavior is going to be different. Let me create a duplicate of this. I sort of had the same question myself, but let me take this out.

And so I'm going to take state. I'm going to bring it in here. Do I want to use all or do I want to use one? Yeah, I'll use all.

Okay, so there it is. I'm going to go over here and I'm going to show a filter. Oh no, I don't like this.

No, Garfield, that's not how you're supposed to do it. What you're supposed to do is you're supposed to change this to a single value list. Okay, so here we go.

This is sort of working okay. Let me click the dropdown. I don't like seeing all 50 states here.

So I'm going to go over here and choose a single value dropdown. Now I'll go here. This seems to be working fine.

Ah, there is, what is the state selector doing here? Let me take it out. I want to make sure that the state selector isn't helping the filter do this. So I want to take this out, edit the parameter.

All right, so I'm going to close. I'm going to take this out. Hide card.

I'll go into the presentation. This is not bad in terms of having this do what the state selector does. But let me go to another sheet.

Let's go to region. Okay, let me go over here and then show the parameter. Okay, so this is, oh yeah, so I show the parameter and then I'm going to go over to state focus and I'm just going to drag it here and then I'll choose true.

It might be a little negligible, but I think one of the advantages is that this is available on multiple sheets, at least the state selector. The filter, you'll have to create from scratch on every sheet. If you're creating a parameter, you have it available on all the sheets.

State focus, as you can see, I didn't create it here. It was already available. All I had to do is drag it in here and select true.

And then just display the state selector. So it's global versus local. And that I would say is at least one of the advantages.

And you may have different reasons why you would use one over the other. But that is definitely a reason to use a parameter. All right, so I'm going to hide this.

I don't want to use this here. And I'm going to take this away. Notice that now the parameter works as intended, but there is another problem.

There is another problem with this. And the problem, if I go back to state selector, I'm going to delete this sheet. I don't have a way to return back to all the states.

I'm stuck. I can only go one state at a time. I'm going to go back and select all the states.

Would I be able to do that with a filter? Yes, I think I would be able to. They do have the option for all. But this doesn't.

I want to build that in. And I want to be able to access it on all the worksheets. We're going to have to edit the state selector, or actually the state focus.

So locate the state parameter, click on it in its menu. And before we had state parameter, although for us it's state selector equals state, we're going to have to do or equal all. We have to go in and edit the state selector.

I'm going to go down here to the bottom and choose edit. I don't have an all as an option. So I'm going to scroll down here and I'm going to add one.

I'm going to say all. Let me make sure I get the spelling right. The value is all.

And I'm going to display it as all states. So all. And then the display is all states.

The display can be whatever I want. But the value has to be all. I'm going to take this and I want to move it all the way to the top.

Because I want it to be at the top. I want it to be the first option from the dropdown. Okay.

So I'm going to do that. And I'm going to click okay. Now I'm going to go and customize my state focus.

Which is available on every single sheet. I only have to change it one place. I'm going to choose edit.

And I'm going to say for state selector equals all. I'm going to copy this part here. Paste.

And then I'll put in double quotes all. Okay. I'll click okay.

This is now already in the sheet and it's working. I'm going to click the dropdown here. When I scroll to the top, I see all states.

I'm going to select all states. And now it returns to all of the states. Now this is a fully customizable control.

I can go to any individual state and I can go to all states. I just needed to go to the state selector, add all as one of the options. How does the map know all is all states? I see it works.

But how does it know? Yeah, it's a syntax thing. So all is a keyword that means all the values in the list. Let's see if there's anything else to go over here.

No, that's basically it. This is one example of creating a custom control. It might not be the one that you're going to use for your project.

But it shows you that something like this is possible. There may be something else that you want to choose to filter by. And maybe it's not state.

And so you can use a custom control for that. And so it's custom to you. It's like a user defined function.

Yeah, but I wondered the same thing when I saw this. I was like, how does all mean all the states? And it's just a syntax thing in Tableau. So that's an example of creating a parameter and then creating a state selector.

Yelp Facebook LinkedIn YouTube Twitter Instagram