0
votes

I've been looking into making a date selector so instead of filtering by Month, Week by adding filters then displaying the quick filters to correspond. I want to be able to dynamically change the date so I can choose between Quarter, Month and Week in a single drop down.

I have made the selector part no problem it shows but when I come to my calculated field, it's not behaving how I would like.

Here is my calculated field:

CASE [Parameters].[Date Select]
WHEN 'Quarter' THEN  QUARTER([Date])
WHEN 'Month' THEN  MONTH([Date])
WHEN 'Week' THEN  WEEK([Date])
END

This gives 2 errors...

Unknown Function QUARTER called
Unknown Function WEEK called

I am puzzled because the month one is fine.

Normally in tableau to get the month/quarter/week, I click on the Date dimension and select Month or week and it filters and displays like so: MONTH(Date).

Can anyone tell me where I'm going wrong and how I can pull the week and quarter from date in the calculated field so my selector will work.

Thanks.

1

1 Answers

1
votes

There are no QUARTER and WEEK functions in Tableau, as you can see in the image below. What you should be using to get these values are:

DATEPART('quarter',[Date])
DATEPART('week',[Date])

Possible date formulas

For filtering the date using your parameter as filter, I'll assume that you want to filter the current quarter, month or week. In this case you'll need to setup your paramaters like this:

Date parameters

Then you'll create a Calculated Field with the following formula:

DATEPART([Date Selector],[Date]) = DATEPART([Date Selector],TODAY())

This should give you a True/False dimension which you will use as filter for the value True. After that you should have a working parameter filtering your data accordingly to the value set.