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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.