Forum Discussion
ivath0
5 years agoFrequent Visitor
Custom Column: End Of Last Month
I want to use Power Query to calculate the number of days between the dates in a Dates column(A) and the end date of last month(B). Eg. Between: (A) 22/6/2020 and (B) 31/01/2021
- 5 years ago
You could take the difference between the start of the current month and column A and subtract a day.
Duration.Days(DateTime.Date(Date.StartOfMonth(DateTime.LocalNow())) - [A]) - 1
AlexisOlson
5 years agoSuper User
You could take the difference between the start of the current month and column A and subtract a day.
Duration.Days(DateTime.Date(Date.StartOfMonth(DateTime.LocalNow())) - [A]) - 1
ivath0
5 years agoFrequent Visitor
Thank you. That works.
And I tried Date.StartOfMonth(DateTime.LocalNow()) - 1) to give just the last date of last month. The syntax is passed but the column just shows errors. How do I correct the errors? And how do I see an explanation of the errors in Power BI?
- v-jingzhang5 years agoCommunity Support
Use Date.AddDays to add or minus number of days.
Date.AddDays(DateTime.Date(Date.StartOfMonth(DateTime.LocalNow())),-1)You can click the error cell to see the error message.
Regards,
Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.