Forum Discussion

ferzfeld's avatar
ferzfeld
Icon for Advocate II rankAdvocate II
5 years ago
Solved

Calculated Column for delta calculation with previous row (lead/lag)

Hello Power BI Community!   I'm struggling with this (probably quite simple 😉 ) DAX problem:   In SQL this would be rather easy to solve using a window function with lead/lag but in DAX... I can...
  • parry2k's avatar
    5 years ago

    ferzfeld add new column using following expression:

     

    Delta New = 
    VAR __currentDate = Delta[entry_date]
    VAR __filter = ALLEXCEPT ( Delta, Delta[kpi_id],Delta[Notes] )
    VAR __previousDate = 
    CALCULATE ( 
        MAX ( Delta[entry_date] ), 
        __filter, 
        Delta[entry_date] < __currentDate 
    )
    VAR __previousSales = 
    CALCULATE ( 
        MAX ( Delta[Actual] ), 
        __filter, 
        Delta[entry_date] = __previousDate 
    )
    RETURN 
    IF ( NOT ISBLANK ( __previousSales ), 
        Delta[Actual] - __previousSales
    )

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.