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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kowalewski92
Frequent Visitor

How to get difference of value between row and previous row and so on...

Hi,

Maybe anyone know that... how can I count difference between row na previous row and so on...? I have that table:

https://imgur.com/a/c6jLo

 

I want to have column that give me difference between rows in fuellevel column but first I want to sort all data by column named as deviceid:

https://imgur.com/a/c6jLo

 

How can I do that?

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @kowalewski92,

 

Since I don't know the other part of your data, I think adding an index would be helpful. In the Query Editor, sort the data by column deviceid, then add an index column. Finally you can add a calculated column to get the result.

difference =
VAR previous =
    CALCULATE (
        SUM ( table1[fuellevel] ),
        FILTER ( table1, table1[Index] = EARLIER ( table1[Index] ) - 1 )
    )
RETURN
    [fuellevel] - previous

How_to_get_difference_of_value_between_row_and_previous_row_and_so_on

 

Best Regards,

Dale

Community Support Team _ Dale
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-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @kowalewski92,

 

Since I don't know the other part of your data, I think adding an index would be helpful. In the Query Editor, sort the data by column deviceid, then add an index column. Finally you can add a calculated column to get the result.

difference =
VAR previous =
    CALCULATE (
        SUM ( table1[fuellevel] ),
        FILTER ( table1, table1[Index] = EARLIER ( table1[Index] ) - 1 )
    )
RETURN
    [fuellevel] - previous

How_to_get_difference_of_value_between_row_and_previous_row_and_so_on

 

Best Regards,

Dale

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

...if you have a date column in the table, you can ignore the index and use this based on previous day in the formula

... = EARLIER ( table1[Date] ) - 1 )

 

Hi, thank you. I have another question. I prepare formula according to your information:

https://imgur.com/jtb4fEJ

 

I got:

https://imgur.com/8xAZD8W

 

But I want to SUM values that have difference in time about 5 minutes (marked as yellow and red). I have car fueling values so you understand. 🙂

 

Maybe you know how can i Do that?

Hi @kowalewski92,

 

You are welcome. I would suggest opening a new thread in this forum due to it's a different question. The point is how you will evaluate the values in 5 minutes.

1. If you want to group the time by 5 minutes, you need to add a new column to identify which 5 minutes the old times belong to.

Old time                     groups

05.11.2017 9:44:15     05.11.2017 9:45:00

05.11.2017 9:46:10     05.11.2017 9:45:00

05.11.2017 9:50:19     05.11.2017 9:45:00

2. If you want to accumulate the previous 5 minutes, that would be a little complex.

 

Best Regards,

Dale

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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
Top Kudoed Authors