Forum Discussion

Tommyvhod's avatar
Tommyvhod
Helper II
3 years ago
Solved

Differentiate operations

Hello all

 

I have a formula which calculates the days between two operations:

 

Aging = var _time =
    MAX(Data[Datum trans])
        VAR _maxLastTime  =
        CALCULATE(MAX(Data[Datum trans]),
        FILTER(ALLEXCEPT(Data, Data[ID]), Data[Datum trans] < _time)
        )
    VAR _datedif =
    DATEDIFF(_maxLastTime,_time,DAY)
    Return
    IF(_datedif >0,_datedif,0)
 
The problem here is that if I have the same date on the last 4 operations and x day before those all the 4 last operations shows x day difference.
I am wondering how could I add another line differenciating the number of the operation ( its always ascending - eg. operation 1, 2 , 5 , 10, 20, etc)
 
Thank you
  • Hi Tommyvhod ,

     

    Based on your description, I have created a simple sample:

    Please try:

    add an index column:

    Then apply the measure:

    Aging = 
    var _time =
        MAX(Data[Datum trans])
    var _index = MAX('Data'[Index])
            VAR _maxLastTime  =
            CALCULATE(MAX(Data[Datum trans]),
            FILTER(ALLEXCEPT(Data, Data[ID]), [Index]=_index-1)
            )
        VAR _datedif =
        DATEDIFF(_maxLastTime,_time,DAY)
        Return
        IF(_datedif >0,_datedif,0)

    Final output:

    Best Regards,

    Jianbo Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Hi Tommyvhod ,

     

    Based on your description, I have created a simple sample:

    Please try:

    add an index column:

    Then apply the measure:

    Aging = 
    var _time =
        MAX(Data[Datum trans])
    var _index = MAX('Data'[Index])
            VAR _maxLastTime  =
            CALCULATE(MAX(Data[Datum trans]),
            FILTER(ALLEXCEPT(Data, Data[ID]), [Index]=_index-1)
            )
        VAR _datedif =
        DATEDIFF(_maxLastTime,_time,DAY)
        Return
        IF(_datedif >0,_datedif,0)

    Final output:

    Best Regards,

    Jianbo Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Thank you. Yes the index column was a good Idea. What I also changed is the

    IF(_datedif >0,_datedif,0)

    To _datedif, Blank()) so the visual wont show unecessary columns