79131273

Date: 2024-10-27 19:01:05
Score: 0.5
Natty:
Report link

I dont have the full context (table names etc.) but based off your requirement, I think you could make use of the WEEKNUM function in PBI.

= WEEKNUM(datetime_column, 2) -- if your week starts on Monday = WEEKNUM(datetime_column, 2) -- if your week starts on Sunday

So your dax query would essentially be:

SumPreviousFourWeeks =

VAR CurrentWeek = WEEKNUM(MAX(YourTable[datetime_column]), 2) // 2 for Monday as start of the week

VAR CurrentYear = YEAR(MAX(YourTable[datetime_column]))

RETURN CALCULATE( SUM(YourTable[YourValueColumn]), FILTER( YourTable, WEEKNUM(YourTable[datetime_column], 2) >= CurrentWeek - 4 && WEEKNUM(YourTable[datetime_column], 2) < CurrentWeek && YEAR(YourTable[datetime_column]) = CurrentYear ) )

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Onga Leo-Yoda Vellem