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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

calculate difference between date vs date -1 & sum the difference

Sorry I'm new to PowerBI and after few hours trying still could not figure out a right way to deal with this:

I got data like this:

Should CALCULATE(SUM())-CALCULATE(SUM()) be used?
DateSome numbersSetDate vs Date -1 Difference
Mar 1100An/a
Mar 1200Bn/a
Mar 2110Ause Mar 2(110)-use Mar 1(100) = 10
Mar 2190Buse Mar 2(190)-use Mar 1(200) = -10
Mar 3120Ause Mar 3(120)-use Mar 2(110) = 10
Mar 3200Buse Mar 3(200)-use Mar 2(190) = 10

 

I want to do two things:
1) calculate the difference between Date vs. Date -1
2) Sum up different of a Set, A = 10+10 = 20, B = -10+10 = 0

A20
B0


And I will keep adding more data of set A & B in coming days.

Hope it's clear enough and I can learn new tricks from you! Thanks in advance!

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

>>1) calculate the difference between Date vs. Date -1

 

Please refer to the dax code for calculated column below:

 

 

DIFF =

IF (

    DATEADD ( 'Table'[Date], -1, DAY ) IN VALUES ( 'Table'[Date] ),

    VAR C = 'Table'[Some numbers]

    VAR Y =

        CALCULATE (

            SUM ( 'Table'[Some numbers] ),

            FILTER (

                'Table',

                'Table'[Date]

                    = EARLIER ( 'Table'[Date] ) - 1

                    && 'Table'[Set] = EARLIER ( 'Table'[Set] )

            )

        )

    RETURN

        C - Y,

    BLANK ()

)

 

 

>>2) Sum up different of a Set, A = 10+10 = 20, B = -10+10 = 0

 

You can create a measure to compute total of different:

 

 

Measure = SUM('Table'[DIFF])

 

 

 

Untitled picture5.png

 

For more details ,please refer to the pbix file : https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ESNDZuuwR_BAmuiwUD...

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

>>1) calculate the difference between Date vs. Date -1

 

Please refer to the dax code for calculated column below:

 

 

DIFF =

IF (

    DATEADD ( 'Table'[Date], -1, DAY ) IN VALUES ( 'Table'[Date] ),

    VAR C = 'Table'[Some numbers]

    VAR Y =

        CALCULATE (

            SUM ( 'Table'[Some numbers] ),

            FILTER (

                'Table',

                'Table'[Date]

                    = EARLIER ( 'Table'[Date] ) - 1

                    && 'Table'[Set] = EARLIER ( 'Table'[Set] )

            )

        )

    RETURN

        C - Y,

    BLANK ()

)

 

 

>>2) Sum up different of a Set, A = 10+10 = 20, B = -10+10 = 0

 

You can create a measure to compute total of different:

 

 

Measure = SUM('Table'[DIFF])

 

 

 

Untitled picture5.png

 

For more details ,please refer to the pbix file : https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ESNDZuuwR_BAmuiwUD...

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

WORK LIKE A CHARM!
The sample file do help me understand the overall calcuation. Thanks a lot for spending time to create that tutorial!!

amitchandak
Super User
Super User

@Anonymous , You can create a new column like

diff = maxx(filter(table,table[set]=earlier(table[set])	 && table[Date]=earlier(table[Date])-1),table[Some numbers]) -table[Some numbers]
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

Well, the first part should be something like:

 

Column =
  Var __Today = [Some numbers]
  VAR __Yesterday = 
    SUMX(
      FILTER(
        'Table',
        [Date]=(EARLIER([Date])-1)*1. &&
          [Set] = EARLIER([Set])
      )
      ,[Some numbers])
RETURN
  __Today - __Yesterday

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.