Calculate the numbers of days between two dates

90 Views Asked by At

I want to calculate the number of days between two dates and plot them against a end date of a given month to determine how may days have passed. I have use this code in DAX:

6M Days =
VAR StartDate =
    MAX ( tblDates[End of Month] )
VAR EndDate =
    DATEADD ( tblDates[End of Month], -6, MONTH )
RETURN
    DATEDIFF ( EndDate, StartDate, DAY )

[enter image description here]

(https://i.stack.imgur.com/Aek4U.png)

However, i got only the months with 31 days in my table. If I us -7 in my formula, i get all the months (with the wrong calculation, sice I need to know 6 months).

I do not understand the logic, maybe you know where the error lies.

1

There are 1 best solutions below

1
Chiến Lê On

You should use EOMonth due to dax query does not behave as normal person would expect

Dateadd vs EOM