Forum Discussion
Anonymous
6 years agoNot applicable
Calculate previous month based on todays date
What is the easiest way to get previous month from today's date? I want to filter dynamic report to previous month. Query1= Date.Month Query2=DateTime.LocalNow Invoked function= (#"Query1"(Query2...
- 6 years ago
Not sure if it is the easiest way but you could do something like this:
=#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()) - 1,Date.Day(DateTime.LocalNow())) - 6 years ago
Hi Anonymous ,
Do you just wanna get the month,if so ,you can use an expression as below:
Previous month=If(Month(Datetime.LocalNow())-1=0,12,Month(Datetime.LocalNow())-1)If you wanna get the date,you can use following expressions:
Previous date=If(Month(DateTime.LocalNow())-1=0,Date(Year(DateTime.LocalNow()),12,Day(DateTime.LocalNow()),Date(Year(DateTime.LocalNow()),Month(DateTime.LocalNow()) - 1,Day(DateTime.LocalNow()))Or you can create a calendar table and create a relationship between the 2 table,finally using an expression as below:
DATEADD ('Calendar'[Date], -1, month)If today is for the real date,you can use today() instead of DateTime.LocalNow().
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
Greg_Deckler
Community Champion
6 years agoNot sure if it is the easiest way but you could do something like this:
=#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()) - 1,Date.Day(DateTime.LocalNow()))