Home > Software design >  Define last week from [date]
Define last week from [date]

Time:01-15

I have issue extracting week/year from DATE column.

We are in week 02 of 2022 and my goal is to set MAX week to be "01 2022" at the moment.

Goal is to have dynamic calculated column or measure that will always show previous week.

weekMax = FORMAT(MAX(fact[date]),"WW YYYY")

With this solution it is showing me 03 2022 result.

Is there a way to sort this out?

CodePudding user response:

You could try something like:

weekMax = 
VAR lastweek = FORMAT(DATEADD('Table'[Date].[Date], -7, DAY) ,"WW YYYY")

RETURN
IF(FORMAT(TODAY() - 7 ,"WW YYYY") = lastweek, lastweek, BLANK())

Output:

enter image description here


Or if you always just want the last week without considering any columns, you can use:

weekMax = FORMAT(TODAY() - 7 ,"WW YYYY")
  •  Tags:  
  • Related