Forum Discussion
Date Filter for last 2 months Data
- Anonymous2 years ago
Hi TARUNEY ,
Have you solved your problem? The function Date.IsInPreviousNMonths will return false when passed a value that occurs within the current month.
Date.IsInPreviousNMonths - PowerQuery M | Microsoft Learn
Please try this:
Here is my sample data and today is 2024.3.25 and I test it in Direct Query mode:
Please use this M function to add a custom column:if [Resolved Date] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2) and [Resolved Date] <= DateTime.Date(DateTime.LocalNow()) and [Resolved Date] <> null then true else if [Resolved Date] = null then null else falseAnd the final output is as below:
Here is the whole M function in the Advanced Editor:
let Source = Sql.Databases("VM0"), test1 = Source{[Name="test"]}[Data], dbo_test = test1{[Schema="dbo",Item="test"]}[Data], #"Added Custom" = Table.AddColumn(dbo_test, "Custom", each if [Resolved Date] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2) and [Resolved Date] <= DateTime.Date(DateTime.LocalNow()) and [Resolved Date] <> null then true else if [Resolved Date] = null then null else false) in #"Added Custom"
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi TARUNEY ,
Have you solved your problem? The function Date.IsInPreviousNMonths will return false when passed a value that occurs within the current month.
Date.IsInPreviousNMonths - PowerQuery M | Microsoft Learn
Please try this:
Here is my sample data and today is 2024.3.25 and I test it in Direct Query mode:
Please use this M function to add a custom column:
if [Resolved Date] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2) and [Resolved Date] <= DateTime.Date(DateTime.LocalNow()) and [Resolved Date] <> null then true else if [Resolved Date] = null then null else false
And the final output is as below:
Here is the whole M function in the Advanced Editor:
let
Source = Sql.Databases("VM0"),
test1 = Source{[Name="test"]}[Data],
dbo_test = test1{[Schema="dbo",Item="test"]}[Data],
#"Added Custom" = Table.AddColumn(dbo_test, "Custom", each if [Resolved Date] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2) and [Resolved Date] <= DateTime.Date(DateTime.LocalNow()) and [Resolved Date] <> null then true else if [Resolved Date] = null then null else false)
in
#"Added Custom"
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.