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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
paultaylor006
Frequent Visitor

Calculate month end dates between two dates

I need to count the number of month end dates between two dates. I've tried using DATEDIFF but cannot quite make this work with the added requirement of counting month end dates.

In the example below I've shown the months count results I would expect to see by calculating the month end dates crossed between the two dates. If the start or end date lands on the month end then they count as being crossed.

Start date     End Date     Months count
01/08/22     30/08/22     0
20/08/22     31/08/22     1
31/08/22     01/09/22     1
31/08/22     30/09/22     2
20/08/22     01/09/22     1
20/08/22     30/09/22     2
20/08/22     31/07/23     12

 

Can anyone suggest a solution to this?

1 ACCEPTED SOLUTION
paultaylor006
Frequent Visitor

I found a slightly different solution by creating an end of month column for the start date, and then then using an end of month calc for the end date but adding a day to the end date to push it into the next month if it fell on the month end date. This allowed me to accruately count month ends.

 

This was the dax I used below and 'StartDate_EndofMonth' iis the  end of month column I created for the start date.

 

Months count = DATEDIFF(EOMONTH('table'[StartDate_EndofMonth],0), EOMONTH('table'[End Date]+1,0),MONTH)

 

View solution in original post

2 REPLIES 2
paultaylor006
Frequent Visitor

I found a slightly different solution by creating an end of month column for the start date, and then then using an end of month calc for the end date but adding a day to the end date to push it into the next month if it fell on the month end date. This allowed me to accruately count month ends.

 

This was the dax I used below and 'StartDate_EndofMonth' iis the  end of month column I created for the start date.

 

Months count = DATEDIFF(EOMONTH('table'[StartDate_EndofMonth],0), EOMONTH('table'[End Date]+1,0),MONTH)

 

johnt75
Super User
Super User

You could add a End of Month column to your date table and then use

Months count =
VAR StartDate =
    SELECTEDVALUE ( 'Table'[Start date] )
VAR EndDate =
    SELECTEDVALUE ( 'Table'[End date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( VALUES ( 'Date'[End of month] ) ),
        DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
    )
RETURN
    Result

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.