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.
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()))
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.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |