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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Employee
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
Employee
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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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