Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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()))-1 gives me the value 2. But I am not able to attach it to the month.
Solved! Go to Solution.
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()))
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().
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().
DATEADD is the function to use for this. It does require a date format field for the date and is able to add or subtract day, month, quarter or year from a given value. Hope that helps
DATEADD (<dates>, <number_of_intervals>, <interval type>)
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()))
User | Count |
---|---|
98 | |
91 | |
82 | |
73 | |
67 |
User | Count |
---|---|
115 | |
102 | |
98 | |
71 | |
66 |