Forum Discussion

Juju123's avatar
Juju123
Helper III
2 years ago
Solved

Calculate the difference between each date

Hello,  I just started on Power BI. I have a table in which I have several columns: I want to calculate the time between each operation: - In yellow, this is the calculation that I wish to ...
  • v-zhangti's avatar
    v-zhangti
    2 years ago

    Hi, Juju123 

     

    This result you expect still requires the addition of the index column. But considering that you are in direct query mode, you can't add it in Power query kind of thing. is the operation code in sequential order?

    Measure:

    Code index = VALUE(RIGHT(SELECTEDVALUE('Table'[Operation code]),3))
    Previous code index = 
    VAR _index = [Code index]
    RETURN
        MAXX ( FILTER ( ALL ( 'Table' ),
                [Code index] < _index
                    && [Article] = SELECTEDVALUE ( 'Table'[Article] )
                    && [Workflow] = SELECTEDVALUE ( 'Table'[Workflow] )
                    && [Designation article] = SELECTEDVALUE ( 'Table'[Designation article] )
            ),
            [Code index]
        )
    Previous date = 
    Var _preindex=[Previous code index]
    Return
    MAXX(FILTER(ALL('Table'),[Code index]=_preindex
                    && [Article] = SELECTEDVALUE ( 'Table'[Article] )
                    && [Workflow] = SELECTEDVALUE ( 'Table'[Workflow] )
                    && [Designation article] = SELECTEDVALUE ( 'Table'[Designation article] )
    
    ),[Operation date])

    Is this the result you expect?

     

    Best Regards,

    Community Support Team _Charlotte

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