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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Subtracting values from the same column but different rows

Hi! 

 

I have an electricity meter that is measuring cumulatively but I need to calculate the difference, therefore, the electricity use each hour. All the electricity data is in one column and I need to, for example, calculate the difference between Row 2-Row 1 for all of the rows. Is there a way to do this in Power BI?

Many thanks for any help you can give me!

 

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Take below simple data as an example.

 

To get the difference between rows via calculated column.

diff =
Table3[Value]
    - CALCULATE (
        SUM ( Table3[Value] ),
        FILTER ( Table3, Table3[Index] = EARLIER ( Table3[Index] ) - 1 )
    )

1.PNG

 

To get difference between rows via measure.

diff measure = 
SELECTEDVALUE ( Table3[Value] )
    - CALCULATE (
        SUM ( Table3[Value] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            Table3[Index]
                = SELECTEDVALUE ( Table3[Index] ) - 1
        )
    )

2.PNG

 

For more advice, please provide your sample data and desired output. How to Get Your Question Answered Quickly

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Take below simple data as an example.

 

To get the difference between rows via calculated column.

diff =
Table3[Value]
    - CALCULATE (
        SUM ( Table3[Value] ),
        FILTER ( Table3, Table3[Index] = EARLIER ( Table3[Index] ) - 1 )
    )

1.PNG

 

To get difference between rows via measure.

diff measure = 
SELECTEDVALUE ( Table3[Value] )
    - CALCULATE (
        SUM ( Table3[Value] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            Table3[Index]
                = SELECTEDVALUE ( Table3[Index] ) - 1
        )
    )

2.PNG

 

For more advice, please provide your sample data and desired output. How to Get Your Question Answered Quickly

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, I tried this and getting error message...

 

MdxScript(Model) (12,162) Calculation error in measure

Hi Yuliana, 

 

If i want to make Row 1 - Row 2 to get the difference, how should the measure look like?

 

Thank you in advance

Greg_Deckler
Super User
Super User

See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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