Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Previous value + 1 with Criteria

Hi Everyone!

A couple of days ago, I asked help to pull the previous value of a row, I was helped here.

Now, I have this code, which returns 1 if the actual value is equal to the previous value, and if doesn't.

Congelamento =
VAR EarlierEntryOfNomeDeOrigem =
    CALCULATE(
        MAX(fminuto[Timestamp]),
        FILTER(
            ALL(fminuto),
            fminuto[Nome da Origem]=SELECTEDVALUE(fminuto[Nome da Origem])
            && fminuto[Timestamp]<MAX(fminuto[Timestamp])
        )
    )

VAR EarlierEntryOfVazao = CALCULATE(
    SELECTEDVALUE(fminuto[Vazão],"no value"),
    FILTER(
        ALL(fminuto),
        fminuto[Nome da Origem]=SELECTEDVALUE(fminuto[Nome da Origem])
        && fminuto[Timestamp] = EarlierEntryOfNomeDeOrigem
    )
)
RETURN
IF(EarlierEntryOfVazao=SELECTEDVALUE(fminuto[Vazão], "no value"), 1, 0)


I would like to, not only show a binary, like 1, but to SUM the previous row with +1 everytime the values are equal, until the sequence is broken by a 0, for example: "0, 1, 2, 3, 4, 5, 6, 7, 0". The objective here is to know how much time the value stayed frozen in sequence. Could anyone help me with this, please?