Forum Discussion
2nd 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 for that store.
The end result would be a table with Store in the Rows, and the following columns 1st Last Score, 2nd Last Score, 3rd Last score
I have a fact table as well as a calendar table:
Here is the measure that I am using to get the average over all of the dates:
TOTAL AVERAGE SCORE = VAR BASE = (IF([CORP %]=BLANK(),BLANK(),1) + IF([FRANCHISE %]=BLANK(),BLANK(),1) + IF([FORECOURTS %]=BLANK(),BLANK(),1)) RETURN ([CORP %]+[FRANCHISE %]+ [FORECOURTS %])/BASE
Here is one of the measures used in the above, the others are the same:
CORP % = Var MyFormChannel = "STORE AUDIT FORM - PNP CORP HYPER AND CHECKERS" RETURN DIVIDE(CALCULATE(COUNTROWS(DATA),DATA[sAnswer]="YES",DATA[FORM TYPE]=MyFormChannel),CALCULATE(COUNTROWS(DATA),DATA[QUESTION]<>"NA",DATA[FORM TYPE]=MyFormChannel))
Regards,
Mark
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 ) )
8 Replies
- Zubair_Muhammad
Community Champion
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 ) )- MarkCBB
Helper V
Hello Zubair_Muhammad,
Thank you, I was able to get this to work. I do however have a question, If I have a look at BP Clubview there is only 1 occurrence. Thus there should be a result, How would I edit this to show the result only if there is a 2nd occurrence.
- Zubair_Muhammad
Community Champion