Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Whoule
Helper I
Helper I

Sum the difference of a value at two different dates

Hi,

 

I am looking to calculate the difference in the "Numberofoutstandingitems" column between the latest date and the one before it. This is updated bi-weekly so it would need to also calculate based on the latest date and the one before it.

Whoule_0-1660930398500.png

 

Thanks in advance for you help with this.

 

1 ACCEPTED SOLUTION

Hi @Whoule 

is column ID coming from the data source. It could be a good helper column to identify which transaction comes first before the others.

 

Try this:

VAR PreviousValue =
    CALCULATE (
        SUM ( Data[Value] ),
        Data[Date] = EARLIER ( Data[ID] ) - 1,
        ALLEXCEPT ( Data, Data[Category] )
    ) // ALLEXCEPT to get the value before the current date per category
RETURN
    Data[Value] - PreviousValue




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @Whoule 

You can use EARLIER to access the data from a row other than the current one. Sample formula as per your use case

Difference =
VAR PreviousValue =
    CALCULATE (
        SUM ( Data[Value] ),
        Data[Date] < EARLIER ( Data[Date] ),
        ALLEXCEPT ( Data, Data[Category] )
    ) // ALLEXCEPT to get the value before the current date per category
RETURN
    Data[Value] - PreviousValue




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi Danextian,

 

The code is working but Var PreviousValue is making the sum of every value past the latest one which is not what I would like to do. I would like it to be only the past value so Latest value - previous value. 

 

 

@danextian Do you have an idea on how to do it?

Hi @Whoule 

is column ID coming from the data source. It could be a good helper column to identify which transaction comes first before the others.

 

Try this:

VAR PreviousValue =
    CALCULATE (
        SUM ( Data[Value] ),
        Data[Date] = EARLIER ( Data[ID] ) - 1,
        ALLEXCEPT ( Data, Data[Category] )
    ) // ALLEXCEPT to get the value before the current date per category
RETURN
    Data[Value] - PreviousValue




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.