Forum Discussion
4 weeks average based on weekrank
- Anonymous6 years ago
Hi Anonymous
I build two table to have a test.
Date Table:
Weeknom and Rank columns are calculated columns.
Weeknom = WEEKNUM('Date'[Date],2)Rank = RANKX('Date','Date'[Date],,DESC,Dense)Result:
Value Table:
Build Value measure in Date table:
Value = CALCULATE(SUM('Value'[Value]),FILTER('Value','Value'[Date]=MAX('Date'[Date])))Then I build a measure to achieve your goal.
4 weeks average = VAR _Totalvalue= SUMX ( FILTER ( ALL ( 'Date' ), 'Date'[Rank] <= MAX ( 'Date'[Rank] ) + 3 && 'Date'[Rank] >= MAX ( 'Date'[Rank] ) ), [Value] ) return IF ( MAXX ( ALL ( 'Date' ), 'Date'[Rank] ) - SUM ( 'Date'[Rank] ) >= 3, DIVIDE(_Totalvalue,4), BLANK() )Result:
You can download the pbix file from this link: 4 weeks average based on weekrank
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
I build two table to have a test.
Date Table:
Weeknom and Rank columns are calculated columns.
Weeknom = WEEKNUM('Date'[Date],2)Rank = RANKX('Date','Date'[Date],,DESC,Dense)
Result:
Value Table:
Build Value measure in Date table:
Value = CALCULATE(SUM('Value'[Value]),FILTER('Value','Value'[Date]=MAX('Date'[Date])))Then I build a measure to achieve your goal.
4 weeks average =
VAR _Totalvalue= SUMX (
FILTER (
ALL ( 'Date' ),
'Date'[Rank]
<= MAX ( 'Date'[Rank] ) + 3
&& 'Date'[Rank] >= MAX ( 'Date'[Rank] )
),
[Value]
)
return
IF (
MAXX ( ALL ( 'Date' ), 'Date'[Rank] ) - SUM ( 'Date'[Rank] ) >= 3,
DIVIDE(_Totalvalue,4),
BLANK()
)
Result:
You can download the pbix file from this link: 4 weeks average based on weekrank
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous this is extremly helpful - but I would like to do it for the last 4 weeks excluding the latest week - so here in this example, I want to average rank 2 to 5 instead of 1 to 4. How can I adjust your formula to do that? Thanks so much!