Forum Discussion

SebastianCostas's avatar
SebastianCostas
Frequent Visitor
3 years ago
Solved

Getting time passed between two dates based on another field

First of all thanks a lot to whoever can help me.   The information I need to calculate is in a single table, and I need to get a column with this value for each row.   I have Purchase Requisitio...
  • v-jingzhang's avatar
    3 years ago

    Hi SebastianCostas 

     

    Please download my sample file to check my solution. 

    I first add an Index column with Power Query, then use below DAX to calculate the spent hours in a calculated column.  

    Time Taken = 
    IF (
        'Table'[Index] = 1,
        DATEDIFF ( 'Table'[PR_Submited], 'Table'[PR_Approved_Date], HOUR ),
        DATEDIFF (
            CALCULATE (
                MAX ( 'Table'[PR_Approved_Date] ),
                ALLEXCEPT ( 'Table', 'Table'[PR_ID] ),
                'Table'[Index]
                    = EARLIER ( 'Table'[Index] ) - 1
            ),
            'Table'[PR_Approved_Date],
            HOUR
        )
    )
    

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.