Forum Discussion
DATEDIFF only returning same value
- 4 years ago
To work properly the time intelligence functions need a date table which contains all the dates for any given year. Create a date table and link it to your fact table, and then use the 'Date'[Date] column instead of the 'Table'[Date] column
Change DATEDIFF to DATEADD, everything else seems fine
Hi johnt75 ,
thank you for your reply. When inserting DATEADD to my command, it returns the following table:
Here is the underlying table if that helps:
Do you happen to have an idea what is going wrong here?
- johnt754 years agoSuper User
To work properly the time intelligence functions need a date table which contains all the dates for any given year. Create a date table and link it to your fact table, and then use the 'Date'[Date] column instead of the 'Table'[Date] column
- ThomasSan4 years agoHelper IV
I was not aware that a separate date table was necessary for time intelligence function to properly work. Thank you for that information!
Unfortunately, the problem persists:
My current DAX command for Test:Test = CALCULATE( sum(SalesTable[International Sales]), DATEADD( 'Date'[Date], -3, MONTH ) )And here is my data model:
I created my date table with the following dax formula:
Date = VAR MinYear = 2021 VAR MaxYear = 2022 RETURN ADDCOLUMNS ( calendar( date(MinYear,1,1) ,Date(MaxYear,12,31) ), "Year", YEAR ( [Date] ), "Month Name", FORMAT ( [Date], "mmmm" ), "Month Number", MONTH ( [Date] ) )Do you see where I might have made a mistake?
Edit:
I found the error. I also needed to adjust the date fields in my matrix. So, rather than using year and month from the date in my sales table, I needed to insert the year and month from my date table. It works now.