sgokce
sgokce

Reputation: 53

Cascading filters on date field on Tableau Desktop

I'm trying to filter my data based on a date field which looks like "01.01.2018 02:00:00". For example, I should firstly select a month of a year, then based on this choice, I should select a week of the month (chosen earlier) and then, I should select a day of this week and so on and so forth until hourly precision. At each choice, my stacked bar should adapt itself to the choice (date axis should be more precise) and filter all the other data. I know that we could expand the date field (hierarchies) but I want this filter to be dynamic. Any help would be appreciated. Thanks in advance!

Upvotes: 1

Views: 805

Answers (1)

tagyoureit
tagyoureit

Reputation: 1286

You can do this with a series of filters that are created by custom calculations.

First, make sure that your field is being recognized as a date.

Tableau Date Dimension.

If it is showing as Abc or another type you can click on the type itself and select date and time.

Next, you will want to make a series of calculations that resolve to your parts of the date. You can use datename('datepart', dateObject) to return names (like January, February, etc) or datepart('datepart', dateObject) to return the numeric values (1, 2, etc). I recommend the datename calculation so you can use dimensions and filtering based on the hierarchy.

The datepart can be many values like year, month, hour, second, etc. See Date Functions for a complete list.

Once you have all of the parts of the date that you want select all of the dimensions, right click on them, and select 'Hierarchy>Create Hierarchy' (you can also do this clicking and dragging dimensions on top of each other). Order (by click/dragging) the dimensions into an appropriate order.

Next, right click on each dimension in your hierarchy and select Show Filter. This will add it to the Filters shelf and display it. (Tip: Tableau will add filters to the top so start with the bottom of your hierarchy so you do not need to reorder them again later.)

Based on creating the hierarchy of dimension values above, Tableau will, by default) make the filters hierarchical.

You can then further refine the ultimate formatting by putting these on a dashboard and customizing the position/styling of the filters.

Lastly, if you have a very large data set this will not be a performant approach as Tableau will need to recalculate all hierarchy filter values with each click. I would suggest sticking with fewer filters (relative dates or selections) or explore a guided analytics approach here.

Upvotes: 1

Related Questions