cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pasno
Helper I
Helper I

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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors