Forum Discussion
MarkCBB
Helper V
8 years ago2nd last date per item
Hi there, I need to create a measure that filters another measure to the 2nd last date. for example, For BP Charles I would like the measure to return the 41.2% score as it is the 2nd last score...
- 8 years ago
Hi Mark MarkCBB
Please try this MEASURE
Measure = VAR SecondLastDate = MINX ( TOPN ( 2, CALCULATETABLE ( VALUES ( TableName[DATE] ), ALLEXCEPT ( TableName, TableName[STORE] ) ), TableName[DATE], DESC ), TableName[DATE] ) RETURN CALCULATE ( [TotalAverageScore], FILTER ( ALLEXCEPT ( TableName, TableName[STORE] ), TableName[DATE] = SecondLastDate ) )
Zubair_Muhammad
Community Champion
8 years ago
Great work Mark.
I wrote a similar revised MEASURE
Measure =
VAR SecondLastDate =
MINX (
TOPN (
2,
CALCULATETABLE (
VALUES ( TableName[DATE] ),
ALLEXCEPT ( TableName, TableName[STORE] )
),
TableName[DATE], DESC
),
TableName[DATE]
)
VAR countdates =
COUNTROWS (
CALCULATETABLE (
VALUES ( TableName[DATE] ),
ALLEXCEPT ( TableName, TableName[STORE] )
)
)
RETURN
IF (
[countdates] > 1,
CALCULATE (
[TotalAverageScore],
FILTER (
ALLEXCEPT ( TableName, TableName[STORE] ),
TableName[DATE] = SecondLastDate
)
)
)
Zubair_Muhammad
Community Champion
8 years ago
Difference is that you had used a MEASURE while I used a VARIABLE
VAR countdates =
COUNTROWS (
CALCULATETABLE (
VALUES ( TableName[DATE] ),
ALLEXCEPT ( TableName, TableName[STORE] )
)
)
- MarkCBB8 years ago
Helper V
Zubair_Muhammad, Thank you so much for your help, I have learnt something new.
Quick question, would there be any performance difference between the 2 approaches?
- Zubair_Muhammad8 years ago
Community Champion