Forum Discussion

drad2211's avatar
drad2211
Frequent Visitor
6 years ago
Solved

dax time difference help

Hi

 

I have a somewhat similar question. I have a table that has the following columns (ID, Time, Action) and I want to add a new column (I believe by making a DAX equation) that can show the time difference (in mins) for specific ID and the 'In' 'Out' Action. I would like the time difference to be shown only on the 'Out' row. The data file is titled 'Data' and the table looks like: 

 

ID                                       Time                             Action

1                            08:00:00 05/05/2015                   In

1                            11:00:00 05/05/2015                  Out

2                            12:00:00 05/05/2015                   In

1                            13:00:00 05/05/2015                   In

1                            15:00:00 05/05/2015                  Out

2                            17:00:00 05/05/2015                  Out

.                                           .                                      .

.                                           .                                      .

 

And I would like the table to look like:

 

ID                                       Time                             Action                     Time Diff

1                            08:00:00 05/05/2015                   In

1                            11:00:00 05/05/2015                  Out                           180

2                            12:00:00 05/05/2015                   In

1                            13:00:00 05/05/2015                   In

1                            15:00:00 05/05/2015                  Out                           120

2                            17:00:00 05/05/2015                  Out                           420

.                                           .                                      .

.                                           .                                      .

 

 

Any advice would be helpful. 

Thank you

  • Hi drad2211 

     

    1. Add the index column in power query

    2. Add the measure below:

    Measure = var a = CALCULATE(MAX('Table (2)'[Time]),FILTER(ALL('Table (2)'),MAX('Table (2)'[Action])="Out"&&[Index]<MAX('Table (2)'[Index])),VALUES('Table (2)'[ID]))
    Return
    DATEDIFF(a,MAX('Table (2)'[Time]),MINUTE)

     

     

5 Replies