Forum Discussion
Previous value with criteria
- 3 years ago
Hi Anonymous ,
I hope I understood your requirement. Typically I highly prefer using measures but in this case I tried it with a calcualted column.
So the following formula identifies in the first place the last relevant row for Nome de Origiem (var_EarlierEntryOfNomeDeOrigem). Based on the time of the last relevant row it gives you back the related value (formula after result).
Value before for name = var EarlierEntryOfNomeDeOrigem = CALCULATE( MAX(fminuto[Timestamp]), FILTER( ALL(fminuto), fminuto[Nome de Origem]=EARLIER(fminuto[Nome de Origem]) && fminuto[Timestamp]<EARLIER(fminuto[Timestamp]) ) ) RETURN CALCULATE( SELECTEDVALUE(fminuto[Value],BLANK()), FILTER( ALL(fminuto), fminuto[Nome de Origem]=EARLIER(fminuto[Nome de Origem]) && fminuto[Timestamp] = EarlierEntryOfNomeDeOrigem ) )Please be aware that if there is no or more than one value for the same time in one category then the formual gives back BLANK(). When there is one distinct previous value for the category (Nome de Origem) then it should work.
Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!
@ me in replies or I'll lose your thread.
Hi Anonymous ,
I also managed to get the result when using a measure.
Measure Version Previous Row of Category =
var EarlierEntryOfNomeDeOrigem =
CALCULATE(
MAX(fminuto[Timestamp]),
FILTER(
ALL(fminuto),
fminuto[Nome de Origem]=SELECTEDVALUE(fminuto[Nome de Origem])
&& fminuto[Timestamp]<MAX(fminuto[Timestamp])
)
)
RETURN
CALCULATE(
SELECTEDVALUE(fminuto[Value],"no value or multiple"),
FILTER(
ALL(fminuto),
fminuto[Nome de Origem]=SELECTEDVALUE(fminuto[Nome de Origem])
&& fminuto[Timestamp] = EarlierEntryOfNomeDeOrigem
)
)
Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!
@ me in replies or I'll lose your thread.
Mikelytics I'm trying to use your measure, but now i have to quantify when the previous value is equal to the actual one, and I tried to use IF 1 or 0, like the code below. Although, It returned only 1's for me. Could you check it out, please?