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
Anonymous
Not applicable

Power Query with add rows with conditions

Hi! I am want to expend my table which records child-parent relationships.

As you see, I want to create a row with for "abc" and set its parent as null. 

How can I do it with powerquery? thanks!

forever_2-1626677703664.png

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

Modify this line a little bit

 Custom1 = List.Distinct(List.Difference(Source[Parent],Source[Child])),

View solution in original post

3 REPLIES 3
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Find the difference between Child and Parent then Table.Combine

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSklNU9JRSkxKVorViVZKz8gE8kBisbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Child = _t, Parent = _t]),
    Custom1 = List.Difference(Source[Parent],Source[Child]),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Child"}}),
    Custom2 = Table.Combine({Source, #"Renamed Columns"})
in
    Custom2

 

Or combine Child and Parent, then Merge

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSklNU9JRSkxKVorViVZKz8gE8kBisbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Child = _t, Parent = _t]),
    Custom1 = List.Union({ Source[Child],Source[Parent]}),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Child"}}),
    #"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Child"}, Source, {"Child"}, "Renamed Columns", JoinKind.LeftOuter),
    #"Expanded Renamed Columns" = Table.ExpandTableColumn(#"Merged Queries", "Renamed Columns", {"Parent"}, {"Parent"})
in
    #"Expanded Renamed Columns"

 

Anonymous
Not applicable

There is a problem with method one.

If "abc" appears twice, two rows will be added.

forever_0-1626682592073.png

 

Hi @Anonymous 

 

Modify this line a little bit

 Custom1 = List.Distinct(List.Difference(Source[Parent],Source[Child])),

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