Forum Discussion

eacy's avatar
eacy
Helper II
10 years ago
Solved

Datediff between dates in groups

Hi,   I would like to DATEDIFF every time I meet a date in column "CFC True" with a date in column "CC True". If there is more dates in the "CC True" column since the last date in "CFC True" colum...
  • v-sihou-msft's avatar
    v-sihou-msft
    10 years ago

    eacy

     

    Please try again with following two formulas which create two calculated columns. It works with the data you posted here.

     

    Min_CC_Since_Last_CFC = 
    
    VAR LastCFCTrue =
    
        IF (
    
            Table1[CFC] = TRUE (),
    
            MAXX (
    
                FILTER ( Table1, Table1[CFC True] < EARLIER ( Table1[CFC True] ) ),
    
                Table1[CFC True]
    
            ),
    
            BLANK ()
    
        )
    
    RETURN
    
        (
    
            IF (
    
                Table1[CFC] = TRUE (),
    
                MINX (
    
                    FILTER (
    
                        Table1,
    
                        Table1[CC] = TRUE ()
    
                            && Table1[CC True] < EARLIER ( Table1[CFC True] )
    
                            && Table1[CC True] > LastCFCTrue
    
                    ),
    
                    Table1[CC True]
    
                ),
    
                BLANK ()
    
            )
    
    )
    

     

     

    CFC_CC_Hour_Diff =
    
    DATEDIFF ( Table1[Min_CC_Since_Last_CFC], Table1[CFC True], HOUR )
    

     

     

  • eacy's avatar
    eacy
    10 years ago

    Hi Simon,

     

    I got my result, thanks a lot.