Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Datadiff returns wrong value

Hi all,   I am calculating a simply date difference using Datediff function. But the value I got is wrong. I check the data types of the two date column are date. I still can not find the reason. P...
  • tamerj1's avatar
    3 years ago

    Hi Anonymous 

    if you change the aggregation from SUM to MAX or MIN you will get correct results at the table visual row level but wrong at the total level. 

    You have two options. 
    first option is to create a measure based on the Date Var column that you have created 

    Difference (days) =
    SUMX (
        SUMMARIZE ( 'Table', 'Table'[Invoice Date], 'Table'[Service/ Tax Date] ),
        CALCULATE ( MAX ( 'Table'[Date Var] ) )
    )

    or directly using the following measure 

    Difference (days) =
    SUMX (
        SUMMARIZE ( 'Table', 'Table'[Invoice Date], 'Table'[Service/ Tax Date] ),
        DATEDIFF ( 'Table'[Service/ Tax Date], 'Table'[Invoice Date], DAY )
    )