Sven
Sven

Reputation: 301

Tableau: Same Day Last Year Auto Filter

I am trying to compare yesterday's data to the same day the year before. For example, yesterday is 11 November 2018. I want to compare to 12 November 2017 (same day but the year before). I am wanting this to be applied automatically on the filter so all I need to do is open the file and verify the numbers are correct before sending off the report.

Any help would be appreciated.

Thanks

Upvotes: 1

Views: 1675

Answers (2)

Alex Blakemore
Alex Blakemore

Reputation: 11896

There are many Tableau functions that manipulate dates. A couple in particular are relevant to your problem:

  • Today() - returns the current date
  • DateAdd() - adds or subtracts an interval from a date. For instance, DateAdd('year', Today(), -1) gives the date one year prior to today. The first argument to DateAdd is the level of granularity or date part.
  • DateDiff() - determines the difference of the interval between two dates. DateDiff('day', [Start Date], [End Date]) returns the number of days separating the two date arguments.

The functions are well documented in the online help. Construct the formulas you need and filter accordingly.

Upvotes: 1

Bernardo
Bernardo

Reputation: 3318

Isolate yesterday's date as its own field. For instance if that is the max date in your data, then {max([Date])} would create an LOD of the maximum date.

Then make a calculation that will display the same date last year:

   year([Date]) = year([max_date])-1
    and datepart('week',[Date]) = datepart('week',[max_date])
    and datepart('weekday',[Date]) = datepart('weekday',[max_date])

Upvotes: 0

Related Questions