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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to create a column that calculates the difference across two rows consecutively?

Hi,

 

Would like to seek some help here.

 

I have a series of data, say an electricity meter (KWH) reading that is being recorded everyday at a fixed time (12am). 

 

I would like to set up a new column calculation in Power BI that calculates the difference between two consective rows; basically the next day's meter reading minus the current day's meter reading. 

 

Can I get some help on how I can do this in Power BI?

 

My sample data looks like this:

 Meter (KWH)Daily Consumption (KWH)
1/8/2019100000100
2/8/2019100100150
3/8/2019100250200
4/8/2019100450150
5/8/2019100600250
6/8/2019100850100
7/8/2019100950200
8/8/2019101150250
9/8/2019101400200
10/8/2019101600 

 

- meter data is recorded everyday at 12am (start of day)

- the data recorded is in the 2nd column (Electricity Meter reading @ 12 AM (KWH))

- the column calculation I am trying to set up is the 3rd column (Daily Consumption (KWH))

- the consumption on 1/8/2019 is thus the meter reading (column 2) data on 2/8/2019 - 1/8/2019

- the last meter reading in this sample is on 10/8/2019 so the electricity consumption for this day is not calculated.

 

Thanks so much for the help!

 

Regards,

Aaron

 

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Try this:

 

 

NewCol =
VAR NextDay_ =
    CALCULATE ( MIN ( Table1[Date] ), Table1[Date] > EARLIER ( Table1[Date] ), ALL(Table1) )
VAR NextDayVal_ =
    CALCULATE ( DISTINCT ( Table1[Meter] ), Table1[Date] = NextDay_ , ALL(Table1))
VAR CurrentDayVal_ = Table1[Meter]
RETURN
    IF ( NOT ISBLANK ( NaxtDay_ ), CurrentDayVal_ - NextDayVal_ )

 

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works as well.

=if(ISBLANK(CALCULATE(MIN(Data[Date]),FILTER(Data,Data[Date]>EARLIER(Data[Date])))),BLANK(),LOOKUPVALUE(Data[Meter (KWH)],Data[Date],CALCULATE(MIN(Data[Date]),FILTER(Data,Data[Date]>EARLIER(Data[Date]))))-Data[Meter (KWH)])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlB
Community Champion
Community Champion

Hi @Anonymous 

Try this:

 

 

NewCol =
VAR NextDay_ =
    CALCULATE ( MIN ( Table1[Date] ), Table1[Date] > EARLIER ( Table1[Date] ), ALL(Table1) )
VAR NextDayVal_ =
    CALCULATE ( DISTINCT ( Table1[Meter] ), Table1[Date] = NextDay_ , ALL(Table1))
VAR CurrentDayVal_ = Table1[Meter]
RETURN
    IF ( NOT ISBLANK ( NaxtDay_ ), CurrentDayVal_ - NextDayVal_ )

 

Anonymous
Not applicable

Thanks, @AlB , it worked!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors