The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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?
Solved! Go to Solution.
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.
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.
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
20 | |
17 | |
15 | |
13 |
User | Count |
---|---|
42 | |
36 | |
23 | |
22 | |
17 |