Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PBIBeginner2022
Helper III
Helper 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 8
JamesRobson
Resolver II
Resolver II

Hi,

 

 Add a new step with the following (amend as per column headers)

= Table.AddColumn(#"Changed Type", "6months", each Date.AddMonths([Date],-6))

 

Thanks,

jennratten
Super User
Super User

Hello - please post an example of your data and the response you are getting after applying your formula.

Thanks @jennratten  for your answer,

 

I want this in Power Query :

Extract_Month bisExtract_Month -6
juil-22null
juil-22null
juil-22null
juil-22null
juin-22null
juin-22null
juin-22null
mai-22null
avr-22null
mars-22null
mars-22null
févr-22févr-22
févr-22févr-22
févr-22févr-22
févr-22févr-22
févr-22févr-22
janv-22null
déc-21null
nov-21null
nov-21null
nov-21null
nov-21null

 

I have no result with my formula above

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

jennratten_0-1658848497179.png

 

@jennratten thanks for your answer,

 

But I would just add a new custom column in my table which have already lot of column .... I can't use this code I think.

Hello again - the solution above creates a table that matches your post "I want this in Power Query".  If you are wanting something different, can you please describe the expected results?  

@jennratten 

 

I have table with lots of column like "Extract_ Month bis". I want added a new column called "Extract_month -6" with the same result that I send you above.

Hello - the result you are requesting matches the outcome of the solution provided.  I have shown them side-by-side below. 

jennratten_0-1658915690709.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors