Forum Discussion
PBIBeginner2022
4 years agoHelper III
Add column with sixth previous month
Hi everyone,
I need to add a new custom column with sixth previous month in Power Query. I thinked to use that formula but it don't function :
= Table.AddColumn(#"Type modifié", "Extract_month M-6", each if Date.IsInPreviousNMonths([Extract_Month bis], -6) then [Extract_Month bis] else null)
Could you help me please.
Thanks in advance for any help
8 Replies
- jennrattenSuper User
Hello - please post an example of your data and the response you are getting after applying your formula.
- PBIBeginner2022Helper III
Thanks jennratten for your answer,
I want this in Power Query :
Extract_Month bis Extract_Month -6 juil-22 null juil-22 null juil-22 null juil-22 null juin-22 null juin-22 null juin-22 null mai-22 null avr-22 null mars-22 null mars-22 null févr-22 févr-22 févr-22 févr-22 févr-22 févr-22 févr-22 févr-22 févr-22 févr-22 janv-22 null déc-21 null nov-21 null nov-21 null nov-21 null nov-21 null I have no result with my formula above
- jennrattenSuper User
Here you are...
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyirNzNE1MlKK1SGanUeInZuYCWMmlhUhRIuKsbHTDq9EKCKHk5WYVwZjpxxemaxrZAhm5+WXEceMBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extract_Month bis" = _t]), ExtractMonth6= Table.AddColumn ( Source, "Extract_Month -6", let varMonths = List.Distinct ( Source[Extract_Month bis] ) in each if [Extract_Month bis] = varMonths{5} then [Extract_Month bis] else null ) in ExtractMonth6
- AnonymousNot applicable
Hi,
Add a new step with the following (amend as per column headers)
= Table.AddColumn(#"Changed Type", "6months", each Date.AddMonths([Date],-6))
Thanks,