Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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))