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.
I have the following code to create a calculated column returning "Yes" if the selected date was last month and "No" for everything else. This was working fine until this month due to the year change. I know what the problem is, but I'm not sure how to correct it.
Here is the custom column code;
if (Date.Year([RequestReceived]) = Date.Year(DateTime.LocalNow()) and Date.Month([RequestReceived]) = Date.Month(DateTime.LocalNow())-1) then "Yes" else "No"
It's clear that the problem is that the code is looking to see if the year matches then looking to see if the month is the current month minus one. This was needed so the formula was taking into account both year and month. Of course, last month's year will not match, so I'm not getting the correct result from the formula. I expect that in February this code will work fine again, but every January it will not. How can I revise this, or better calculate if the date in the selected field was last month?
Thanks,
Shawn
Solved! Go to Solution.
Hi, In Pquery yo can create a Custom Column with this code.
=if Date.IsInPreviousNMonths([Request_Recieved], 1)=true then "Yes" else "No"
Regards
Thank you both for the quick reply. @Vvelarde This was exactly what I needed and works like a charm.
Hi, In Pquery yo can create a Custom Column with this code.
=if Date.IsInPreviousNMonths([Request_Recieved], 1)=true then "Yes" else "No"
Regards
Seems like you could nest your if statements such that you first check if the current month is 1 and if so then see if the month for the date is 12 and if so Yes, otherwise, your current calculation.
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 |
---|---|
111 | |
95 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |