cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ah2020
Frequent Visitor

DAX: What is wrong with my EOMONTH formula?

I have a model with a table called "MthYrTxt". It is not my date dimension (calendar) table but it has a "date" column, properly formatted as date.

The table looks as follows:

 

dateMthYrSortOrder
2019-07-01Jul 2019

1

2019-08-01Aug 20192
2019-09-01Sep 20193
2019-10-01Oct 20194
2019-11-01Nov 20195
2019-12-01Dec 20196

 

I need a Measure that will give the last date of each date mentioned in the table above.

That is, 2019-07-01 as 2019-07-31, 2019-08-01 as 2019-08-31, 2019-09-01 as 2019-09-30 and so on.

I also need a second Measure that will give me the numbers of days for each month mentioned in that table: 31, 31 , 30 and so on.

 

I have tried these measures to get the last day of the Month but they are not working properly:

 

LastDayOfMonth = EOMONTH(MthyrTaxt[date])

LastDayOfMonth = ENDOFMONTH)(MthYrTxt[date)]

 

What am I doing wrong?

 

I am stuck with the Measure to get the number of days!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User I
Super User I

Re: DAX: What is wrong with my EOMONTH formula?

@ah2020 

 

An alternative way to calculate the days in a month is:

eomonth.JPG

- the ENDOFMONTH function returns the last date in the month in the date filter context.

- the DAY funtion returns the day number for the ENDOFMONTH date, so in effect it is the number of days in the month.




If this post has helped you, please give it a thumbs up!
Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

4 REPLIES 4
Super User III
Super User III

Re: DAX: What is wrong with my EOMONTH formula?

Hey @ah2020 , 

 

I used these DAX statements to create calculated columns:

 

 

Last Day of Month = EOMONTH('Table'[date] , 0)

 

 

Number of Days = DATEDIFF(DATE(YEAR('Table'[date]) , MONTH('Table'[date]) , 1) , 'Table'[Last Day of Month] , DAY) + 1

 

 

and these statements to create measures:

 

 

ms Last Day of Month = EOMONTH(MAX('Table'[date]) , 0)

 

 

ms Number of Days = 
var _year = YEAR(MAX('Table'[date]))
var _month = MONTH(MAX('Table'[date]))
var _yearLast = YEAR(MAX('Table'[Last Day of Month]))
var _monthLast = MONTH(MAX('Table'[Last Day of Month]))
var _dayLast = DAY(MAX('Table'[Last Day of Month]))
return
DATEDIFF(DATE(_year , _month , 1) , DATE(_yearLast , _monthLast , _dayLast) ,  DAY) + 1

 

A table visual will look like this:

image.png

 

Hopefully, this is what you are looking for.

 

Regards,
Tom

 

 

Hamburg - Germany
If I answer your question, please mark my post as solution, this will also help others.
I accept Kudos :-), If you find my post helpful.

Proud to be a Datanaut!
Super User I
Super User I

Re: DAX: What is wrong with my EOMONTH formula?

@ah2020 

 

An alternative way to calculate the days in a month is:

eomonth.JPG

- the ENDOFMONTH function returns the last date in the month in the date filter context.

- the DAY funtion returns the day number for the ENDOFMONTH date, so in effect it is the number of days in the month.




If this post has helped you, please give it a thumbs up!
Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

Super User III
Super User III

Re: DAX: What is wrong with my EOMONTH formula?

Hey @PaulDBrown ,

 

of course, I will try to change my habit 🙂

Never thought of this.

 

Regards,

Tom

Hamburg - Germany
If I answer your question, please mark my post as solution, this will also help others.
I accept Kudos :-), If you find my post helpful.

Proud to be a Datanaut!
Super User I
Super User I

Re: DAX: What is wrong with my EOMONTH formula?

@TomMartens 

 

Great to hear! It's pretty cool when you find that DAX has little gems hidden up its sleeve!




If this post has helped you, please give it a thumbs up!
Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors