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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pasno
Helper II
Helper II

Help with Date DATEADD

Hello guys,

I'm making an error using DATEADD function but I don't know how to fix / how to do it in a different way.

 

Actually I have this formula to get the start date I need, and it works, but if I put it into a table it is affected by the OrderID, so for each line i get a different TESTDATE:

TESTDATE =
VAR LAST_DATE = ENDOFMONTH(Orders[OrderDate])
RETURN
STARTOFMONTH(DATEADD(LAST_DATE; -1; MONTH))

 

I would like to get a fixed value, based not on the date of each order but simply based on my last order (so last date available in my colums.

 

Should be something like this, but it doesn't work:

TESTDATE =
VAR LAST_DATE = CALCULATE(ENDOFMONTH(Orders[OrderDate]); ALL(ID))
RETURN
STARTOFMONTH(DATEADD(LAST_DATE; -1; MONTH))

 

Do you have an idea to solve it?

 

Thank you in advance!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@pasno , eomonth and dateadd work with continuous date. Try like this example

 

TESTDATE =
VAR LAST_DATE = ENDOFMONTH(Orders[OrderDate])
RETURN
Eomonth(date(year(LAST_DATE);month(LAST_DATE) -1; day(LAST_DATE)),-1)+1

 

or

 

TESTDATE =
VAR LAST_DATE = CALCULATE(ENDOFMONTH(Orders[OrderDate]); ALL(ID))
RETURN
Eomonth(date(year(LAST_DATE);month(LAST_DATE) -1; day(LAST_DATE)),-1)+1

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@pasno , eomonth and dateadd work with continuous date. Try like this example

 

TESTDATE =
VAR LAST_DATE = ENDOFMONTH(Orders[OrderDate])
RETURN
Eomonth(date(year(LAST_DATE);month(LAST_DATE) -1; day(LAST_DATE)),-1)+1

 

or

 

TESTDATE =
VAR LAST_DATE = CALCULATE(ENDOFMONTH(Orders[OrderDate]); ALL(ID))
RETURN
Eomonth(date(year(LAST_DATE);month(LAST_DATE) -1; day(LAST_DATE)),-1)+1

Nice workaround, it works!

 

Thank you very much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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