Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

DAX for date difference

Hi, I have 2 dates "Start Date" and "End Date", I have to create a new column with the difference of these 2 dates as highlighled below. I want the new column to show up as 4/1/2021-4/30/2021...
  • FrankAT's avatar
    FrankAT
    5 years ago

    Hi Anonymous ,

    so here is a third variation:

     

     

    Difference in Month = 
    VAR _StartLessThanEnd =
    IF (
        OR ( 'Table'[Start], 'Table'[End] ) = BLANK (),
        BLANK (),
        DATEDIFF ( 'Table'[Start], 'Table'[End], MONTH ) + 1
    )
    VAR _EndLessThanStart =
    IF ( 
        OR ( 'Table'[Start], 'Table'[End] ) = BLANK (),
        BLANK (),
        DATEDIFF ( 'Table'[End], 'Table'[Start], MONTH ) + 1
    )
    RETURN
        if ( 'Table'[Start] < 'Table'[End], _StartlessThanEnd, _EndLessThanStart)

     

    With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
    FrankAT (Proud to be a Datanaut)