Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculate difference with cumulative total

I have a dataset that has a running total (cumulative total) but need to be able to create a column that tracks the difference by date and category. Everything I've found online seems to show how to ...
  • lc_finance's avatar
    6 years ago

    Hi Anonymous ,

     

     

    You can download my proposed solution from here.

     

    Here is the formula for Value Savings:

    Value savings = 
    var currentDate = SELECTEDVALUE(Savings[Date])
    var priorDate = CALCULATE(LASTDATE('Savings'[Date]), ALLEXCEPT('Savings','Savings'[uniqueID]),'Savings'[Date]<currentDate)
    RETURN 
    SUM('Savings'[Cumulative Savings]) - CALCULATE(SUM('Savings'[Cumulative Savings]), ALLEXCEPT('Savings',Savings[uniqueID]), 'Savings'[Date]=priorDate)

    this is how the formula works:

    first, it finds the current date

    second, it finds the prior date for the same uniqueID

    finally, it calculates the difference between the cumulated savings on the current date and the cumulated savings on the prior date.

     

    Here is a screenshot of the final result:

     

    Does this help you?

     

    LC

    Interested in Power BI and DAX tutorials? Check out my blog at www.finance-bi.com