Forum Discussion

Nandor's avatar
Nandor
Helper I
9 years ago
Solved

How to extract the values from two consecutive rows

Hi,

 

I have measurements of an equipment that produces tablets. The operator logs the value that the machine shows every 15 minutes. This value shows how many tablets were produced from the last reset.

I would like to see how many tablets were produced between two consecutive measurements.

 

My data looks like this:

 

Date&Time Measurement

 

Date&TimeMeasurement
01/06/2016 06:000
01/06/2016 06:3012000
01/06/2016 07:0022000
01/06/2016 07:3030000
01/06/2016 08:0044000
01/06/2016 08:3058000
01/06/2016 09:0072000
01/06/2016 09:3080000
01/06/2016 10:00102000

 

I would need to add a new column that shows every 30 minutes how many tablets were produced. My table should be like this:

 

Date&TimeMeasurementTablets produced between two measurements
01/06/2016 06:0000
01/06/2016 06:301200012000
01/06/2016 07:002200010000
01/06/2016 07:30300008000
01/06/2016 08:004400014000
01/06/2016 08:305800014000
01/06/2016 09:007200014000
01/06/2016 09:30800008000
01/06/2016 10:0010200022000

 

Thank you for the help.

Nandor

  • Hi Nandor. One way to do it would be to add an Index column to your dataset. While you're in the query editor, you can go to Add Column > Add Index Column. Then you can go to the Data view and Add New Column where you subtract the row where the index is one less the current row. Something like:

     

    Column = TableName[Tablets] - LOOKUPVALUE(TableName[Tablets], TableName[Index], TableName[Index]-1)

     

    Just be sure your data is sorted properly before adding the Index column!

     

2 Replies

  • KGrice's avatar
    KGrice
    Memorable Member

    Hi Nandor. One way to do it would be to add an Index column to your dataset. While you're in the query editor, you can go to Add Column > Add Index Column. Then you can go to the Data view and Add New Column where you subtract the row where the index is one less the current row. Something like:

     

    Column = TableName[Tablets] - LOOKUPVALUE(TableName[Tablets], TableName[Index], TableName[Index]-1)

     

    Just be sure your data is sorted properly before adding the Index column!