Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Timediff between 2 rows depending on index+filter

Hi,

 

How would I calculate the Time Difference depending on an Index column and a filter?

 

Example:

 

An Indeks column is added,

Filter: shiftid

 

Waste Start: 2022-03-02 08:17:23

Running Start: 2022-03-02 07:15:34

 

Wanted result: Time Difference (format could be seconds..)

 

 

  • Anonymous , In case you need a measure

     

    new column =
    var _max = maxx(filter(allselected(Table), [Index] < max([Index]) && [shift ID] = max( Table[shift ID] )),[Index])
    return
    datediff(maxx(filter(allselected(Table), [Index] =_index && [shift ID] = max( Table[shift ID] )),[Waste Stop]),, Min([Waste Start]), second)

2 Replies

  • Anonymous , In case you need a measure

     

    new column =
    var _max = maxx(filter(allselected(Table), [Index] < max([Index]) && [shift ID] = max( Table[shift ID] )),[Index])
    return
    datediff(maxx(filter(allselected(Table), [Index] =_index && [shift ID] = max( Table[shift ID] )),[Waste Stop]),, Min([Waste Start]), second)

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you amitchandak ,

     

    I changed the name of the varible (from: _index to _var) and removed one of the "," where double - after that it seemed to work,

     

    Only thing left is that all the values ought to be in the above location (lower Indeks-value),

    How would I correct that in the code?

     

     

    Running (Seconds) =
    var _max = 
    maxx (
    filter ( allselected (Waste) ,
    [Indeks] < max( [Indeks] ) && [shiftId] = max( Waste [shiftId] )) ,
    [Indeks]
    )
    
    return
    
    datediff (
    maxx ( filter ( allselected (Waste) , 
    [Indeks] = _max && [shiftId] = max(  Waste [shiftId] ) ) ,
    [Waste Stop] ) ,
    Min( [Waste Start] ) ,
    second
    )