Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DATEDIFF for repeated rows

Hey everybody! I have an issue and would be appreciated for your help.   I have a table below that contains information about power station's working time. Column 1 shows us when station works prop...
  • tamerj1's avatar
    tamerj1
    3 years ago

    Hi Anonymous 
    It was a wrong solution.

    Please refer to attached file with the correct solution

     

    Down Order = --column 
    IF ( 
        'Nizhny Tagil#1'[HP GOX] = 1,
        RANKX ( 
            FILTER ( 'Nizhny Tagil#1', 'Nizhny Tagil#1'[HP GOX] = 1 ),
            VAR T1 = FILTER ( 'Nizhny Tagil#1', 'Nizhny Tagil#1'[Date] <= EARLIER ( 'Nizhny Tagil#1'[Date] ) )
            RETURN
                COUNTROWS (T1)
                - SUMX (
                    T1,
                    'Nizhny Tagil#1'[HP GOX]
                ),, 
                ASC, 
                Dense
        )
    )
    Start Time = --measure
    IF ( 
        NOT ISBLANK ( SELECTEDVALUE ( 'Nizhny Tagil#1'[Down Order] ) ),
        MIN ( 'Nizhny Tagil#1'[Date] )
    )
    End Time = --measure
    IF ( 
        NOT ISBLANK ( SELECTEDVALUE ( 'Nizhny Tagil#1'[Down Order] ) ),
        MAX ( 'Nizhny Tagil#1'[Date] )
    )
    Downtime = --measure
    SUMX (
        VALUES ( 'Nizhny Tagil#1'[Down Order] ),
        IF (
            'Nizhny Tagil#1'[Down Order] <> BLANK (),
            DATEDIFF ( [Start Time], [End Time], MINUTE )
        )
    )