Forum Discussion
Help with Date_request in Date.IsInPreviousNMonths
- 3 years ago
Hi , Anders_G
Accoding to your description, you want to filter the previous N months od the last year. Right?
I mean this , you can put this in "Advanced Editor" in Power Query Editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc3BDQAhCETRXjib4ODqQi3G/ttYJJrl+vIzMydJFWEwqBBolQsu3UnkGsLGtpbQGLoNTwrrCZEsHsYPnc3h1SOw2HfS5lPrAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"value", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>if Duration.Days(Date.AddDays(Date.From(Date.From(DateTime.LocalNow())),-365)-x[Date]) >=0 and Duration.Days(Date.AddDays(Date.From(Date.From(DateTime.LocalNow())),-365)-x[Date]) <=60 then 1 else -1 ) in #"Added Custom"The table is like this:
Then we can filter the [Custom]=1 then we will meet your need .
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , Anders_G
The "Date.IsInPreviousNMonths" function is automatically compared with the current time of the system, and the comparison date cannot be customized.
For more information, you can refer to:
Date.IsInPreviousNMonths - PowerQuery M | Microsoft Learn
If you want to import X months in the past from the previous year . I think you need to calculate the days between two days and then compare the days to filter your table.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Thank you for the clarification.
If you want to import X months in the past from the previous year . I think you need to calculate the days between two days and then compare the days to filter your table.
I would be very grateful if you could explain the process in more detail. I have no real knowledge of M or SQL. I mostly copy and paste what I can find on this forum.
- v-yueyunzh-msft3 years agoCommunity Support
Hi , Anders_G
Accoding to your description, you want to filter the previous N months od the last year. Right?
I mean this , you can put this in "Advanced Editor" in Power Query Editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc3BDQAhCETRXjib4ODqQi3G/ttYJJrl+vIzMydJFWEwqBBolQsu3UnkGsLGtpbQGLoNTwrrCZEsHsYPnc3h1SOw2HfS5lPrAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"value", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>if Duration.Days(Date.AddDays(Date.From(Date.From(DateTime.LocalNow())),-365)-x[Date]) >=0 and Duration.Days(Date.AddDays(Date.From(Date.From(DateTime.LocalNow())),-365)-x[Date]) <=60 then 1 else -1 ) in #"Added Custom"The table is like this:
Then we can filter the [Custom]=1 then we will meet your need .
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly