Forum Discussion
Anonymous
7 years agoNot applicable
Creating a flag for previous month
Hi, Im trying to create a flag for when a provider is new in the previous month. I want the previous months data to have a 1 and everything else to have a 0. I'm struggling to find a date fu...
- 7 years ago
the code I posted can only replace 4 in your example, try this:
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each if [Provider start date] > #date(Date.Year(Date.StartOfMonth(DateTime.FixedLocalNow())-#duration(1,0,0,0)), Date.Month(Date.StartOfMonth(DateTime.FixedLocalNow())-#duration(1,0,0,0)), 1) then 1 else 0),
- 7 years ago
Hi Anonymous,
there are build-in date functions which you can use: Date.IsInPreviousMonth and Date.IsInCurrentMonth.
let DateToTest = #date(2019, 5, 5), Result = { Date.IsInPreviousMonth(DateToTest), Date.IsInCurrentMonth(DateToTest) } in ResultUsage in your case:
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each if Date.IsInPreviousMonth([Provider start date]) or Date.IsInCurrentMonth([Provider start date]) then 1 else 0),
or even shorter if you expect just a logical type (True/False as result):
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each Date.IsInPreviousMonth([Provider start date]) or Date.IsInCurrentMonth([Provider start date]), type logical),
Stachu
7 years agoCommunity Champion
the code I posted can only replace 4 in your example, try this:
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each if [Provider start date] > #date(Date.Year(Date.StartOfMonth(DateTime.FixedLocalNow())-#duration(1,0,0,0)), Date.Month(Date.StartOfMonth(DateTime.FixedLocalNow())-#duration(1,0,0,0)), 1) then 1 else 0),
Nolock
7 years agoResident Rockstar
Hi Anonymous,
there are build-in date functions which you can use: Date.IsInPreviousMonth and Date.IsInCurrentMonth.
let
DateToTest = #date(2019, 5, 5),
Result = {
Date.IsInPreviousMonth(DateToTest),
Date.IsInCurrentMonth(DateToTest)
}
in
ResultUsage in your case:
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each if Date.IsInPreviousMonth([Provider start date]) or Date.IsInCurrentMonth([Provider start date]) then 1 else 0),
or even shorter if you expect just a logical type (True/False as result):
#"Added Conditional Column" = Table.AddColumn(#"Sorted Rows", "Provider is new last month", each Date.IsInPreviousMonth([Provider start date]) or Date.IsInCurrentMonth([Provider start date]), type logical),