3
votes

My (simplified) data structure is as follows:

enter image description here

I have flagged whether my users have performed a certain action in the last 7 days, 14 days, 1 month, 6 months, and 1 year (1 means the user has performed the action and 0 means he has not). I would like to create a drop-down filter in Tableau where I would be able to filter out the users who have performed the action in the last 7 days, 14 days, 1 month, 6 months, and 1 year. I will have a total number of users at the top of my dashboard and an "action date" filter. Does anyone know how I can achieve this kind of filter in Tableau? I believe I have to create a parameter but I am not sure how to combine these 5 columns into 1 filter.

Any help is appreciated!

2
what you wish to achieve is called pivoting a tableshripal mehta

2 Answers

4
votes

The easiest approach to explain is to create a parameter that allows the user to select exactly one value from a prescribed list of strings, such as "7 days", "14 days"... etc. You may also want a few other choices like "Start of Time", or "All users". Whatever options you like.

Then create a (boolean) calculated field that denotes whether the current data record should be included based on the current parameter value. Something like

if [My Filter Param] = "7 Days" then
   [7 Days] = 1
elseif [My Filter Param] = "14 Days" then
   [14 Days] = 1
...
else // last one
   [My Filter Param] = "Start of Time"
end

Then put your calculated field on the filter shelf, choose True as the filter value, apply to whatever worksheets or data sources matter, and of course display your parameter control.

This is a pretty general technique, combine a parameter (for asking the user to make a choice) with a boolean calculated field (to apply the users choice) and the filter or other shelf for applying that calculation to a visualization. Works for all kinds of problems.

If your data sets are large or slow, you can optimize performance in a few ways. Say by using boolean fields in your data instead of integers, and by using integer valued parameters instead of strings so you can use a fast case statement to replace all the string comparisons (although Tableau can optimize some of those comparisons away) If you do use an integer parameter, you can still define the choices to display meaningful strings in the parameter control. See the edit parameter dialog.

Finally, you could consider making your analysis and viz a little more flexible by adjusting your pre-processing to produce data with just two columns -- User and Date_of_Last_Key_Action . Then your users could just use the built-in date filter controls in Tableau to view based on any time range, .e.g, the last 13.5 days if they wanted. You wouldn't need a parameter or calculated field in that case.

3
votes

You can also re-shape your data. Do like the screenshot GIF

enter image description here