KNOWLEDGE BASE

Calculations For Last N Weeks Measure For This Year And Last Year


Published: 17 Sep 2020
Last Modified Date: 17 Sep 2020

Question

Calculations for last n weeks measure for this year and last year. Example: Showing measure value for last n weeks for this year until Today and same last n weeks for last year

Environment

  • Tableau Desktop

Answer

This year last n weeks :

if [Date]> DATEADD('week',-(n-1), DATETRUNC('week',TODAY())) and
[Date]<=DATEADD('week',1, DATETRUNC('week',TODAY()))
THEN [Value] end

Last year last n weeks:

if [Date]>= DATEADD('week',-(n-1), DATETRUNC('week',DATEADD ('year',-1,TODAY())))
and [Date]<=DATEADD('week',1, DATETRUNC('week',DATEADD('year',-1 ,TODAY())))
THEN [Value] end


 

Additional Information

Note:  Please change the dates to reflect latest dates in the attached workbook to check the calculations
Did this article resolve the issue?