Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
How do I calculate the number of months between two dates in PowerQuery? I can figure it out in DAX but can't seem to find the syntax to make it work in PowerQuery as a custom coloumn.
For example:
Start Date: 01/12/2020
End Date: 01/03/2020
= 4 months
Solved! Go to Solution.
It is easiest to use DATEDIFF with MONTH on the DAX side, but in Power Query you can use the formula below. It isn't exact but may work for you.
= Duration.TotalDays([EndDate]-[StartDate])/30
If within the same year, you can use Date.Month([EndDate]) - DateMonth([StartDate])
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I know this is very old thread, i've landed here searching for a quick solution.
I found none are really useful. So i've figured out by myself. Below is the solution.
Number.Abs(Date.Year(Date.EndOfMonth([To]))+Date.Month(Date.EndOfMonth([To]))/12-Date.Year([From])-Date.Month([From])/12)*12 + 1
All the answers here are bad.
Correct answer can be see in this questions comments (User lbendlin:)
https://community.powerbi.com/t5/Power-Query/Date-difference-in-Months-Power-Query/td-p/1993216
Extract from that:
Date.Year([Date2])*12+Date.Month([Date2])-Date.Year([Date1])*12-Date.Month([Date1])
Hi,
See if this helps - Generating Rows by Month for Date Ranges in Power Query | by Daniel Marsh-Patrick | Daniel Marsh-Pat...
The first one works across years. Please share that part of your M code to troubleshoot.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
It is easiest to use DATEDIFF with MONTH on the DAX side, but in Power Query you can use the formula below. It isn't exact but may work for you.
= Duration.TotalDays([EndDate]-[StartDate])/30
If within the same year, you can use Date.Month([EndDate]) - DateMonth([StartDate])
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thanks @mahoneypat , I've tried both those solutions but they don't work as it's not accurate and goes over various years.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
70 | |
67 | |
51 | |
39 | |
26 |
User | Count |
---|---|
87 | |
55 | |
45 | |
42 | |
36 |