Forum Discussion

mariana_carmof's avatar
mariana_carmof
Frequent Visitor
4 years ago
Solved

Return immediately previous value

Hi everyone!   I need to check if my previous status is different from my current one. However, the initial comparison to proceed with my code does not return what I want. In image formula, MAX re...
  • mariana_carmof's avatar
    4 years ago

    Hey speedramps!
    Thanks for your answer!

    I wanted to compare the "Status" column of the most recent date with the "Status" of the previous most recent date for a sku. 

    I solved the problem as follows:

     
    Alteracao_status_semanal =
    VAR DATA_ANTERIOR = CALCULATE(MAX('Mkp combinado'[Data]),FILTER (ALLEXCEPT ( 'Mkp combinado','Mkp combinado'[Mkp - SKU]),'Mkp combinado'[Data] < EARLIER ( 'Mkp combinado'[Data] ) ))
    VAR STATUS_ANTERIOR = CALCULATE(MAX('Mkp combinado'[Status Mkp]), FILTER(ALLEXCEPT('Mkp combinado','Mkp combinado'[Mkp - SKU]),'Mkp combinado'[Data] = DATA_ANTERIOR))
    VAR ALTERACAO_STATUS = SWITCH(
    TRUE(),
    STATUS_ANTERIOR = "", "Sem histórico",
    STATUS_ANTERIOR = 'Mkp combinado'[Status Mkp], "Inalterado",
    STATUS_ANTERIOR = "Ativo" && 'Mkp combinado'[Status Mkp] = "Inativo", "Desativado",
    "Ativado")
    RETURN
    ALTERACAO_STATUS