I load tables based on the current month thru yesterday. On the first of the month, I need to load the entire previous month because we look at data in the month thru the previous day.
Is there a way to use an if statement that says if day of the current month = 1, use Date.IsInPreviousMonth([Date]) else
= Table.SelectRows(#“Changed Type”, each
Date.IsInCurrentMonth([Date]) and [Date] < Date.From(DateTime.LocalNow()))
I feel you where so close to solving it…
See if this works for you. I used this Date table M code and named that query fxCalendar, next add a new blank query and paste in the code below.
let
Source = fxCalendar(#date(2017, 1, 1), #date(2022, 12, 31), null, null, null, null),
Today = #date(2021, 2, 1), //Date.From(DateTime.LocalNow()),
FilterDates = Table.SelectRows( Source, each (if Date.Day(Today)=1 then Date.IsInPreviousMonth([Date]) else Date.IsInCurrentMonth([Date]) and [Date] < Today ))
in
FilterDates
Thanks Melissa for responding. I’ve done what you posted. I am unclear on how it will work. Do I need to refilter my tables to use this or is this some kind of global query for the report that will be used?
I am not very familiar with M Code. . I pasted let
Source = fxCalendar(#date(2017, 1, 1), #date(2022, 12, 31), null, null, null, null),
Today = #date(2021, 2, 1), //Date.From(DateTime.LocalNow()),
FilterDates = Table.SelectRows( Source, each (if Date.Day(Today)=1 then Date.IsInPreviousMonth([Date]) else Date.IsInCurrentMonth([Date]) and [Date] < Today ))
in
FilterDates
as a step to filter on my table. I also tried just using FilterDates and get We cannot convert the value “FilterDates” to type Table.