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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Preetish_1
Helper I
Helper I

Calculating difference between ROWS

Hi everyone,

 

I am new to Power BI and DAX and I'm finding it difficult to find the difference between two rows.
As shown in the sample data, I have many Machine codes, and cumulative values of thier operating hours and cycles are available in the table. The data is in no particular order, and I would like to be able to find the hours and cylces for a particular month by calculating the difference between two consecutive months as a Calculated Column or a Measure.

 

 

Table.PNG

 

 

Any help would be greatly appreciated.

Regards,

Preetish

 

 

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

@Preetish_1,

 

You may create calculated columns as shown below.

CurrentDate =
DATEVALUE (
    RIGHT ( Table1[Date], 4 ) & "-"
        & MID ( Table1[Date], 4, 2 )
        & "-"
        & LEFT ( Table1[Date], 2 )
)
Difference =
VAR Prev =
    CALCULATE (
        SUM ( Table1[Values] ),
        ALLEXCEPT ( Table1, Table1[MC Code], Table1[Type] ),
        PREVIOUSMONTH ( Table1[CurrentDate] )
    )
RETURN
    IF ( ISBLANK ( Prev ), BLANK (), Table1[Values] - Prev )
Community Support Team _ Sam Zha
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

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Preetish_1,

 

You may create calculated columns as shown below.

CurrentDate =
DATEVALUE (
    RIGHT ( Table1[Date], 4 ) & "-"
        & MID ( Table1[Date], 4, 2 )
        & "-"
        & LEFT ( Table1[Date], 2 )
)
Difference =
VAR Prev =
    CALCULATE (
        SUM ( Table1[Values] ),
        ALLEXCEPT ( Table1, Table1[MC Code], Table1[Type] ),
        PREVIOUSMONTH ( Table1[CurrentDate] )
    )
RETURN
    IF ( ISBLANK ( Prev ), BLANK (), Table1[Values] - Prev )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @vanessafvg, I tried it but I did not know how to filter the data.

Thank you very much @v-chuncz-msft , your recommendation works perfectly.

Thanks for your help.

 

 

vanessafvg
Community Champion
Community Champion

@Preetish_1 have you tried previous month?  https://msdn.microsoft.com/en-us/library/ee634758.aspx

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors