Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
juliany
Frequent Visitor

DATEADD not working on certain date values

I have a calculated column in my data set (DataTable2019 Test) which is looking at a date column (History Date) subtracting one year from the date and then returning a custom formatted date. For full context here I'm trying to show the Jan 1st dates as the year end (YE) count for that given year.

 

This is the formula below:

Datetable2019 Test = FORMAT(DATEADD('Employee History'[History Date], -1, YEAR), """YE"" yyyy")
 
The formula works perfectly for the 2021, 2022 and 2023 dates in the History Date column, but for the 2020 dates I am getting back blank.
 
Separately, I seem to have lost the ability for a matrix using this column to be sorted by date. Instead it's being sorted alphabetically.
 
Please help!
1 ACCEPTED SOLUTION
AUaero
Responsive Resident
Responsive Resident

I'm guessing your date table doesn't have dates prior to 2020.  DATEADD doesn't work by adding or subtracting from a given date, it returns a result from your date table shifted by the interval you've specified.  If no dates exist prior to 2020, you won't get a result.  Take a look at the DATEADD documentation for more info.
DATEADD function (DAX) - DAX | Microsoft Docs

View solution in original post

5 REPLIES 5
NehaSingh_108
New Member

Hey,

Try adding .[Date] to your date column name while using it to create a DAX. 
For example, 

Created Date (Corrected) = IF(YEAR('Raw Dump'[Created Date])="2022", DATEADD('Raw Dump'[Created Date].[Date],-1,year),'Raw Dump'[Created Date])
Andrew59
Regular Visitor

I had the same issue with DATEADD and adding multiple years to a certain column. EDATE works perfect in this case EDATE(<date-field, ,nr of months>)

AUaero
Responsive Resident
Responsive Resident

I'm guessing your date table doesn't have dates prior to 2020.  DATEADD doesn't work by adding or subtracting from a given date, it returns a result from your date table shifted by the interval you've specified.  If no dates exist prior to 2020, you won't get a result.  Take a look at the DATEADD documentation for more info.
DATEADD function (DAX) - DAX | Microsoft Docs

That makes sense, thank you.

 

is there another function that can just subtract 1 year from the date in the history table? 

so for the 2020 dates in my table, they would return a result of "YE 2019".

 

AUaero
Responsive Resident
Responsive Resident

Take a look at the EDATE function

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.