Search box in Tableau
Today we’ll be learning to create a Search Box in Tableau dashboard. I have used ‘Superstore’ data for the tutorial.
Create Parameter and Filters
Creating Parameter-
For the first step we’ll be creating a parameter. So right click in the Parameters area and click on ‘Create Parameter’ and create a blank string parameter as shown in the image below. I’ve named it ‘Search Box’
Create Calculated field for Filter-
Now we’ll be creating a filter. We have used Tableau CONTAINS function and following is the calculated field.
So the formula works as:
Contains("String", "SubString to find")
Returns true if the given string contains the specified sub-string.
Our formula working as whatever we type in the search box it will look in both State and Category Dimension and if it is present it will return the value.
CONTAINS(([State]),[Search Box]) OR CONTAINS(([Category]),[Search Box])
Creating Chart and Search Box
Now we’ll be creating the chart. Add Category and Discount in Columns shelf and State to Rows shelf.
Add the calculated field we just created (Search Filter in this case) to filters card.
Click on the Search Box parameter click on ‘Show Parameter Control’
and that’s done.
Example– As you can see in the image below while searching ‘califo’ it will show all the state or category which contains califo as sub-string.
This search boxes are very useful when any field contains long texts as values.
Hello! My name is MaryMarkova, our compane need to advertise on your website. What is your prices? Thank you. Best regards, Mary.
Hi Mary,
Please have a look at Advertise
My sheet is blank until and unless I have some value in the textbox. How can I change this behavior in such a way that when the search text is null then display the complete data?
Can you elaborate your issue or mail at admin@analytics-tuts.com.
My sheet is displaying all the data before entering some value in textbox, how do i change it to making the sheet empty and the data appearing only when some value in entered in the text box?
Hi Ishani,
Change your calculation field to something like this:-
IF [Search Box]=”” or [Search Box]=” ” THEN FALSE
ELSEIF CONTAINS(([State]),[Search Box]) = TRUE
OR
CONTAINS(([Category]),[Search Box]) = TRUE THEN TRUE
END
Let me know if this solves your issue.
Thanks for visiting Analytics Tuts.
The page doesnt load up if there is nothing in the search box. I want the whole data to load if there is nothing given in the search box
Change the calculated field without any space in that case.
Please tell me what is the change required to show all values by default if nothing is entered in the search box
Please try the below,
This will show all values by default if nothing is entered in the search box,
IF [Search Box]=”” or [Search Box]=” ” THEN TRUE
ELSEIF CONTAINS(([State]),[Search Box]) = TRUE
OR
CONTAINS(([Category]),[Search Box]) = TRUE THEN TRUE
END
How to add a comment like “Type in..” in the parameter search bar when my table is empty. So users can understand.
Hi,
Thanks for sharing the tips!
Does the dimension used as the search need to be in the view for the search box to work?
In your example, you have both Category and State in the view, that’s why you can search by them. what if we use a dimension, “country” for example, which is not in the view, will the search box work?
I have this issue in the data set that I’m working on.
Thank you!
It will work even if it is not in the view
Actually, I realized it’s Cap issue. The search I type in the search box has to match exactly the Upper and Lower cases of the values. For example, “retail” doesn’t work, but “RETAIL” works because that’s how the string value is in the data set. Could you help?
Thank you!
You can change the calculated field to :
CONTAINS(UPPER(([State])),UPPER([Search Box]))
OR
CONTAINS(UPPER([Category]),UPPER([Search Box]))
how do I create the calculated field if the thing im searching is integers?
CONTAINS only works on strings
Use STR function to convert it to string and then use it.
Thanks,
Niket
Example of values: Safe Driver Report, Safe Driver Exceptions, Safe Drivers, Safe hand sanitizers – COVID, Safe and Sound Visualization
When i use the parameter with a list, it only allows the first position to be searched and i can only key in ‘S’
With your example, using the Contains function in the parameter calculation, it allows keying of the name up until the first space. Is it possible to include the space to allow continued keystrokes until the user finds the exact value they are looking for?
Also wondering if i can do a fuzzy search in tableu that would provide a sublist of all values that contain the keyword(s) ‘SAFE DRIVER’ or COVID?
I’m using this with a list in the parameters. When that happens, it enables the first portion of the value of value to be searched and allows multiple keystrokes
Hello Niket Kedia,
i didnt get i want to show all the values if nothing is typed in search box. It should show all the values.
what change i need to do the calculation
hello,
I want my page to be blank at first and then load based on what user enters in the search field. The suggested is not working for me. Could you please let me know if there is a work around.
IF [Search Box]=”” or [Search Box]=” ” THEN FALSE
ELSEIF CONTAINS(([State]),[Search Box]) = TRUE
OR
CONTAINS(([Category]),[Search Box]) = TRUE THEN TRUE
END
Try with ISNULL calculation
Hello,
It is so helpful post! Thank you for your blog.
One question here though.
I am using multiple data sources, and try to make search box effecting across the multiple sources. I have tried choose the field name from different data source in calculation, but it gives errors.
Also, the parameter itself in dashboard does not have the function to apply to other sheets.
Do you know how I can make it happen?
Thanks!
Hi, you have to keep the parameter in all the dashboards you have and use the same field name as you have in the data source.
Thanks:)
Hi! Is there a way to make the search not case-sensitive? For example, to search license and LICENSE and receive the same results? Thank you!
I figured it out – add both UPPER and LOWER to each calculation.
Great 🙂
Hi, this is so great, I’m not sure if it’s possible to bold or highlight in the chart the word searched in the box
Need to check that.