Forum Discussion
TopN returns different results when adding additional column
- 5 years ago
Hi lancea,
Try measure as:
8wk_Total = VAR LastWeek = MAX ( Query1[Week] ) VAR Last8Weeks = TOPN (8, FILTER ( ALL ( Query1[Week] ), Query1[Week] <= LastWeek ), Query1[Week], DESC) RETURN CALCULATE ( SUM ( Query1[Sales] ), FILTER(ALL('Query1'),Query1[Week] IN Last8Weeks )Here is the output:
If you still have some question, please don't hesitate to let me known.
Best Regards,
Link
Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!
lancea , In such case better to have separate week or date table, That will allow you to all or allselected of table then column
8wk_Total =
VAR LastWeek = MAX ( Query1[Week] )
VAR Last8Weeks = TOPN (8, FILTER ( ALL ( Week[Week] ), Query1[Week] <= LastWeek ), Query1[Week], DESC)
RETURN
CALCULATE ( SUM ( Query1[Sales] ), Last8Weeks )
Sorry, this does not work and returns error in the formula:
For reference, I created a Week_Table using the formula:
- amitchandak5 years agoSuper User
lancea , change topN like and try
TOPN(10,filter(all(WeekTable[Week]), WeekTable[Week] <=max(WeekTable[Week])),WeekTable[Week],DESC)
- lancea5 years agoHelper I
It works now but unfortunately, I still get the same results:
Here is my formula for 8wk_separate:
8wk_separate = VAR LastWeek = MAX ( Query1[Week] )VAR Last8Weeks = TOPN(10,filter(all(Week_Table[Week]), Week_Table[Week] <=max(Week_Table[Week])),Week_Table[Week],DESC)RETURNCALCULATE ( SUM ( Query1[Total PO lines due this week (CRD)] ), Last8Weeks )