cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Calculating difference between consecutive rows

Hi, I am new to Bi and having a hard time in calculating the difference between consecutive rows for a particular ID.

 

bi.png

 

I want to caculate the difference between consecutive volume for a particular "Unique ID". 

As the ID changes, the cumulative difference calculation should correspond to that particular "Unique ID"

 

Thnaks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Calculating difference between consecutive rows

Hi @hmeegada,

 

1. Add an index in the Query Editor. 

2. Add a calculated column with the formula below.

Column =
VAR currentIndex = [Index]
VAR currentVolume = [Volume.Volume]
VAR lastVolume =
    CALCULATE (
        MIN ( Table1[Volume.Volume] ),
        FILTER (
            ALLEXCEPT ( 'Table1', Table1[Unique ID] ),
            Table1[Index]
                = currentIndex - 1
        )
    )
RETURN
    IF ( ISBLANK ( lastVolume ), 0, currentVolume - lastVolume )

Calculating-difference-between-consecutive-rows

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

5 REPLIES 5
Highlighted
Super User I
Super User I

Re: Calculating difference between consecutive rows

@hmeegada Could you please post the sample data in copiable format and also provide the expected output which will be helpful.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Microsoft
Microsoft

Re: Calculating difference between consecutive rows

Hi @hmeegada,

 

What's the expected result? Since the "Unique" is unique, you can just calculate the number of "Unique".

[Unique]    count('table'[Unique])

 

 

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.
Highlighted
Frequent Visitor

Re: Calculating difference between consecutive rows

Hi,  I have provided a sample data below for your reference and the last column is the expected result

 

The difference between consecutive rows should continue for a particular Unique ID and as soon as the Unique ID changes, the difference between consecutive rows should correspond to that particular Unique ID.

 

Site #ProductTank #Volume.Inventory DateVolume.VolumeUnique IDExpected Result
0711150DIESEL310/18/2018 4:54:00 AM11797071115030
0711150DIESEL310/18/2018 5:26:00 AM11797071115030
0711150DIESEL310/18/2018 5:41:00 AM11797071115030
0711150DIESEL310/18/2018 5:56:00 AM11797071115030
0711150DIESEL310/18/2018 6:11:00 AM11797071115030
0711150DIESEL310/18/2018 6:26:00 AM11797071115030
0711150DIESEL310/18/2018 6:41:00 AM11797071115030
0711150DIESEL310/18/2018 6:56:00 AM1178207111503-15
0711150DIESEL310/18/2018 7:11:00 AM11782071115030
0711150DIESEL310/18/2018 7:26:00 AM11782071115030
0711150DIESEL310/18/2018 7:41:00 AM11782071115030
0711150DIESEL310/18/2018 7:56:00 AM11782071115030
0711150DIESEL310/18/2018 8:11:00 AM11782071115030
0711150DIESEL310/18/2018 8:26:00 AM11782071115030
0711150DIESEL310/18/2018 8:41:00 AM11782071115030
0711150DIESEL310/18/2018 8:56:00 AM11782071115030
0711150DIESEL310/18/2018 9:11:00 AM11782071115030
0711150DIESEL310/18/2018 9:26:00 AM11782071115030
0711150DIESEL310/18/2018 9:41:00 AM1175907111503-23
0711150DIESEL310/18/2018 9:56:00 AM1169107111503-68
0711150DIESEL310/18/2018 10:11:00 AM11691071115030
0711150DIESEL310/18/2018 10:26:00 AM11691071115030
0711150DIESEL310/18/2018 10:41:00 AM1165407111503-37
0711150DIESEL310/18/2018 10:57:00 AM11654071115030
0711150DIESEL310/18/2018 11:11:00 AM11654071115030
0711150DIESEL310/18/2018 11:26:00 AM11654071115030
0711150DIESEL310/18/2018 11:41:00 AM11654071115030
0711150DIESEL310/18/2018 11:56:00 AM11654071115030
0711150DIESEL310/18/2018 12:11:00 PM11654071115030
0711150DIESEL310/18/2018 12:26:00 PM11654071115030
0711150DIESEL310/18/2018 12:41:00 PM1163107111503-23
0711150DIESEL310/18/2018 12:56:00 PM11631071115030
0711150REG110/18/2018 4:54:00 AM33130071115010
0711150REG110/18/2018 5:26:00 AM3308007111501-50
0711150REG110/18/2018 5:41:00 AM3304607111501-34
0711150REG110/18/2018 5:56:00 AM3301607111501-30
0711150REG110/18/2018 6:11:00 AM33016071115010
0711150REG110/18/2018 6:26:00 AM3299707111501-19
0711150REG110/18/2018 6:41:00 AM3295507111501-42
0711150REG110/18/2018 6:56:00 AM3292907111501-26
0711150REG110/18/2018 7:11:00 AM3286507111501-64
0711150REG110/18/2018 7:26:00 AM3285007111501-15
0711150REG110/18/2018 7:41:00 AM3276207111501-88
0711150REG110/18/2018 7:56:00 AM3274407111501-18
0711150REG110/18/2018 8:11:00 AM3253907111501-205
0711150REG110/18/2018 8:26:00 AM3222907111501-310
0711150REG110/18/2018 8:41:00 AM3216107111501-68
0711150REG110/18/2018 8:56:00 AM3198307111501-178
0711150REG110/18/2018 9:11:00 AM3188107111501-102
0711150REG110/18/2018 9:26:00 AM3160407111501-277
0711150REG110/18/2018 9:41:00 AM3157007111501-34
0711150REG110/18/2018 9:56:00 AM3150607111501-64
0711150REG110/18/2018 10:11:00 AM3144107111501-65
0711150REG110/18/2018 10:26:00 AM3140007111501-41
0711150REG110/18/2018 10:41:00 AM3125607111501-144
0711150REG110/18/2018 10:57:00 AM3119507111501-61
0711150REG110/18/2018 11:11:00 AM3116107111501-34
0711150REG110/18/2018 11:26:00 AM3107407111501-87
0711150REG110/18/2018 11:41:00 AM3087807111501-196
0711150REG110/18/2018 11:56:00 AM3084007111501-38
0711150REG110/18/2018 12:11:00 PM3068107111501-159
0711150REG110/18/2018 12:26:00 PM3063507111501-46
0711150REG110/18/2018 12:41:00 PM3052907111501-106
0711150REG110/18/2018 12:56:00 PM3040107111501-128
0711150PREM210/18/2018 4:54:00 AM13970071115020
0711150PREM210/18/2018 5:26:00 AM13970071115020
0711150PREM210/18/2018 5:41:00 AM13970071115020
0711150PREM210/18/2018 5:56:00 AM1395507111502-15
0711150PREM210/18/2018 6:11:00 AM13955071115020
0711150PREM210/18/2018 6:26:00 AM13955071115020
0711150PREM210/18/2018 6:41:00 AM13955071115020
0711150PREM210/18/2018 6:56:00 AM13955071115020
0711150PREM210/18/2018 7:11:00 AM13955071115020
0711150PREM210/18/2018 7:26:00 AM13955071115020
0711150PREM210/18/2018 7:41:00 AM13955071115020
0711150PREM210/18/2018 7:56:00 AM13955071115020
0711150PREM210/18/2018 8:11:00 AM13955071115020
0711150PREM210/18/2018 8:26:00 AM13955071115020
0711150PREM210/18/2018 8:41:00 AM1393207111502-23
0711150PREM210/18/2018 8:56:00 AM1387207111502-60
0711150PREM210/18/2018 9:11:00 AM13872071115020
0711150PREM210/18/2018 9:26:00 AM13872071115020
0711150PREM210/18/2018 9:41:00 AM13872071115020
0711150PREM210/18/2018 9:56:00 AM1383007111502-42
0711150PREM210/18/2018 10:11:00 AM13834071115024
0711150PREM210/18/2018 10:26:00 AM13834071115020
0711150PREM210/18/2018 10:41:00 AM13834071115020
0711150PREM210/18/2018 10:57:00 AM1381907111502-15
0711150PREM210/18/2018 11:11:00 AM1380707111502-12
0711150PREM210/18/2018 11:26:00 AM13807071115020
0711150PREM210/18/2018 11:41:00 AM1375007111502-57
0711150PREM210/18/2018 11:56:00 AM13750071115020
0711150PREM210/18/2018 12:11:00 PM1370907111502-41
0711150PREM210/18/2018 12:26:00 PM13709071115020
0711150PREM210/18/2018 12:41:00 PM13709071115020
0711150PREM210/18/2018 12:56:00 PM1364807111502-61
0711157PREMIUM210/18/2018 5:02:00 AM38849071115720
0711157PREMIUM210/18/2018 5:35:00 AM38849071115720
0711157PREMIUM210/18/2018 5:50:00 AM38853071115724
0711157PREMIUM210/18/2018 6:05:00 AM38853071115720
0711157PREMIUM210/18/2018 6:20:00 AM38853071115720
0711157PREMIUM210/18/2018 6:35:00 AM38853071115720
0711157PREMIUM210/18/2018 6:50:00 AM38853071115720
0711157PREMIUM210/18/2018 7:05:00 AM38853071115720
0711157PREMIUM210/18/2018 7:20:00 AM38853071115720
0711157PREMIUM210/18/2018 7:35:00 AM38853071115720
0711157PREMIUM210/18/2018 7:50:00 AM38853071115720
0711157PREMIUM210/18/2018 8:05:00 AM38853071115720
0711157PREMIUM210/18/2018 8:20:00 AM3880007111572-53
0711157PREMIUM210/18/2018 8:35:00 AM3878807111572-12
0711157PREMIUM210/18/2018 8:50:00 AM38788071115720
 PREMIUM210/18/2018 9:05:00 AM3872807111572-60
0711157PREMIUM210/18/2018 9:20:00 AM38728071115720
0711157PREMIUM210/18/2018 9:35:00 AM3872407111572-4
0711157PREMIUM210/18/2018 9:50:00 AM38724071115720
0711157PREMIUM210/18/2018 10:05:00 AM38724071115720
0711157PREMIUM210/18/2018 10:20:00 AM38724071115720
0711157PREMIUM210/18/2018 10:35:00 AM3870507111572-19
0711157PREMIUM210/18/2018 10:50:00 AM38705071115720
0711157PREMIUM210/18/2018 11:05:00 AM38705071115720
0711157PREMIUM210/18/2018 11:20:00 AM38705071115720
0711157PREMIUM210/18/2018 11:35:00 AM38705071115720
0711157PREMIUM210/18/2018 11:50:00 AM38705071115720
0711157PREMIUM210/18/2018 12:05:00 PM38705071115720
0711157PREMIUM210/18/2018 12:20:00 PM3868207111572-23
0711157PREMIUM210/18/2018 12:35:00 PM38682071115720
0711157PREMIUM210/18/2018 12:50:00 PM3866307111572-19
0711157PREMIUM210/18/2018 1:05:00 PM3865207111572-11
0711157RUL110/18/2018 5:02:00 AM33739071115710
0711157RUL110/18/2018 5:35:00 AM3373507111571-4
0711157RUL110/18/2018 5:50:00 AM3368207111571-53
       

 

Thanks

Highlighted
Microsoft
Microsoft

Re: Calculating difference between consecutive rows

Hi @hmeegada,

 

1. Add an index in the Query Editor. 

2. Add a calculated column with the formula below.

Column =
VAR currentIndex = [Index]
VAR currentVolume = [Volume.Volume]
VAR lastVolume =
    CALCULATE (
        MIN ( Table1[Volume.Volume] ),
        FILTER (
            ALLEXCEPT ( 'Table1', Table1[Unique ID] ),
            Table1[Index]
                = currentIndex - 1
        )
    )
RETURN
    IF ( ISBLANK ( lastVolume ), 0, currentVolume - lastVolume )

Calculating-difference-between-consecutive-rows

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

Highlighted
Microsoft
Microsoft

Re: Calculating difference between consecutive rows

Hi @hmeegada,

 

Could you please mark the proper answers as solutions?

 

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

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors