Forum Discussion
Bug? - IsInNextNMonths
- 4 years ago
Both Date.IsInNextNMonths and Date.IsInPreviousMonths ignore the current month, because the current month is not in the next months, you cannot use either as an absolute for future/past. You'd need to use an OR condition with Date.IsInCurrentMonth. and is after today.
for example:
Date.IsInNextNMonths([Date], 6) or (Date.IsInCurrentMonth([Date]) and [Date] > DateTime.Date(DateTime.LocalNow()))With today being June 14, 2022...
- 4 years ago
I thought this made sense, but it's throwing an error for the affected lines. I'll update with errors soon.
It also did not fix the problem of June 26th showing within the next 12 months.
I still think there's a bug regarding what it considers a month
Perfect, so I got the 2 month to work, but I'm still unhappy with the time intelligence.
With 'else if Date.IsInNMonths([Security Expiration Date]), 12) then "12" '
I expect June 26th 2023, to come out as 18, because it's not in the next 12 months, but got 12.
When I changed it to "else if Date.IsInNMonths([Security Expiration Date]), 11) then "12", I got 18...
But I also got 18 on 7 June -12 June as well, which is wrong.
Do I have to use some complicated formula of
else if Date.IsInNMonths([Security Expiration Date]), 12) - current day or something?
June 26, 2023 is in the next 12 months. This is June 2022. The next 12 months are July, August, Sept...April, May, June 2023.
You are wanting it to look at the next 365 days or something, and if that is the case, use Date.IsInNextNDays([Date],365) which would seem to work better for you unless a leap year messed it up by one day for a particular calc. But remember, Date.IsInNextNDays(#date(2022,6,16),30) will return false, because today is not in the next N days. You still have to account for the current day as I showed in previous posts.
So the answers you are getting from Power Query are not wrong. You just have a different expectation of what the formula is calculating.