Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello Experts!
I have Start Date and End Date as columns and I want to get number of months between the dates. But I will not be able to use formula:
Number.Round(Number.From(([ENDDATE] - [STARTDATE])/( 365.25 / 12 )) ,0 ) +1
Reason is, I want to take the whole month despite of the date. As an example.
STARTDATE | ENDDATE | Number of months |
2/1/2022 | 2/1/2023 | 13 |
7/15/2022 | 3/15/2023 | 9 |
10/15/2021 | 11/30/2021 | 2 |
6/30/2022 | 9/30/2022 | 4 |
3/1/2023 | 4/30/2025 | 26 |
How can I arrive this in Power Query? Basically, I want to extract the month of each date and subtract and add one. But this is impossibe when years are different. Please help!
Solved! Go to Solution.
I think following formula would work as you want to take complete month
= Number.RoundUp(Duration.Days(Date.EndOfMonth([ENDDATE])-[STARTDATE])/(365.25/12))
OR
= Number.RoundUp(Duration.Days(Date.EndOfMonth([ENDDATE])-Date.StartOfMonth([STARTDATE]))/(365.25/12))
Hi @Anonymous ,
Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your problem.
Best Regards,
Stephen Tao
Power Quer
=(Date.Year([ENDDATE]) -Date.Year([STARTDATE]))*12 + (Date.Month([ENDDATE])-Date.Month([STARTDATE]))+1
or, if you are using Power BI, you could use:
DAX
Number of Months = DATEDIFF([STARTDATE],[ENDDATE],MONTH)+1
I think following formula would work as you want to take complete month
= Number.RoundUp(Duration.Days(Date.EndOfMonth([ENDDATE])-[STARTDATE])/(365.25/12))
OR
= Number.RoundUp(Duration.Days(Date.EndOfMonth([ENDDATE])-Date.StartOfMonth([STARTDATE]))/(365.25/12))
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.