Forum Discussion

sergiogonzalez's avatar
sergiogonzalez
Regular Visitor
6 years ago
Solved

Calculate date between changes of status

Hi, i need to calculate the time between each change of status, i have an index (ID_HISTORIAL) For example: The time between 843453 and 844104 is 2 days. The time between 844104 and 845402 i...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi sergiogonzalez 

    I build a new table to achieve your goal.

    Firstly I build an Index column like before.

    var _rank =
    
    RANKX (
    
        FILTER ( 'Table', 'Table'[ID TARER] = EARLIER ( 'Table'[ID TARER] ) ),
    
        'Table'[FECHA ENTREGADO].[Day],
    
        ,
    
        ASC,
    
        DENSE
    
    )

    Then I build a new calculated column to calculate the days between each changes of column "estado".

    Time = 
    VAR _Lastestado =
        CALCULATE (
            SUM ( 'Table'[ESTADO] ),
            FILTER ( 'Table', 'Table'[var _rank] = EARLIER ( 'Table'[var _rank] ) - 1 )
        )
    VAR _DATE1 =
        MAXX (
            FILTER (
                'Table',
                'Table'[ID TARER] = EARLIER ( 'Table'[ID TARER] )
                    && 'Table'[var _rank] < EARLIER ( 'Table'[var _rank] )
            ),
            'Table'[FECHA ENTREGADO]
        )
    VAR _DATE2 = 'Table'[FECHA ENTREGADO]
    RETURN
        IF (
            'Table'[var _rank] = 1,
            1,
            IF ( 'Table'[ESTADO] - _Lastestado <> 0, DATEDIFF ( _DATE1, _DATE2, DAY ), 1 )
        )

    Result:

    You can download the pbix file from this link: Calculate date between changes of status

     

    Best Regards,

    Rico Zhou

     

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