tableau-apicalculated-fielddatefilter

Leave out Current Week with Calculated Field


I need to leave out the current week. I have found a way of doing it with this calculated field:

[Current Week Filter]

DATEDIFF('week',DATETRUNC('week',[Reporting Day],'Sunday'),

DATETRUNC('week',TODAY(),'Sunday')) >= 1

I also created a filter:

[Exclude Current Filter]

if [Current Week Filter] then 
     'Yes' 
else 
     'No'
end

It works! However, if I want to include the current week along with the other ones, I have to either: remove the filter or short-circuit it by selecting True AND False.

In other words, I'd like an 'Exclude Filter' that when 'Yes' is selected it leaves out the current week and when 'No' is checked, everything is shown.

I'm sure that it's a silly thing... Maybe it's the calculated field or the Yes/No switch...

Any Help?


Solution

  • Assuming your data does not have future dates, you can do this with a parameter and a filter. Create an integer parameter with the following:

    param

    Then create a filter that compares the week difference between the max week and week in the data with the parameter.

    datediff('week',[Date],{max([Date])})>=[week]
    

    Set this in the filter shelf to True. Toggle the parameter to include/exclude as needed.