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

Creating hierarchy

Hello community,

could someone supply me a power query m formula which can do the following. I've tried for so long: 

inf1948_0-1636474275247.png


Colum CC-Col should contain all appropriate 25642 values and the result should look like this 

 

inf1948_1-1636474308766.png

 

 

thank you in advance

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Just merge on C-Col = P-Col Left Outer then expand C-Col from the nested table.

This method gives me the following ouput:

BA_Pete_0-1636476486941.png

 

Paste this over the default code in a new blank query to follow the steps I took:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxCcBADEPRXVS78vnbySzH7b9GTAgEV4InaW/5IkOmRRA69guJT/EOH9Kf/DZvZyoopkRRQ5Lr7s15AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"P-Col" = _t, #"C-Col" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"P-Col", Int64.Type}, {"C-Col", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"C-Col"}, #"Changed Type", {"P-Col"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"C-Col"}, {"C-Col.1"})
in
    #"Expanded Changed Type"

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
smpa01
Community Champion
Community Champion

@Anonymous  try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxCcBADEPRXVS78vnbySzH7b9GTAgEV4InaW/5IkOmRRA69guJT/EOH9Kf/DZvZyoopkRRQ5Lr7s15AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"P-Col" = _t, #"C-Col" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"P-Col", Int64.Type}, {"C-Col", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
   Search = #"Changed Type"[#"P-Col"],
   Lookup = #"Changed Type"[#"C-Col"],
   Loop = List.Generate(
                        ()=>[i=List.PositionOf(Search,[#"C-Col"]),j=try Lookup{i} otherwise -999],
                        each [j]<>-999,
                        each [i=[i]+1, j=try Lookup{i} otherwise -999],
                        each [j]
   ) in Loop),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
    #"Expanded Custom"

 

 

smpa01_0-1636477082629.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Just merge on C-Col = P-Col Left Outer then expand C-Col from the nested table.

This method gives me the following ouput:

BA_Pete_0-1636476486941.png

 

Paste this over the default code in a new blank query to follow the steps I took:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcuxCcBADEPRXVS78vnbySzH7b9GTAgEV4InaW/5IkOmRRA69guJT/EOH9Kf/DZvZyoopkRRQ5Lr7s15AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"P-Col" = _t, #"C-Col" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"P-Col", Int64.Type}, {"C-Col", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"C-Col"}, #"Changed Type", {"P-Col"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"C-Col"}, {"C-Col.1"})
in
    #"Expanded Changed Type"

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




AlexisOlson
Super User
Super User

I think you should be able to expand CC-Col. If that icon isn't showing you might need to replace those "blank" cells with proper nulls as discussed recently here: https://community.powerbi.com/t5/Desktop/Custom-columns-in-a-SharePoint-Page-Library/m-p/2176571

 

Take a look at the last two steps in this sample query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2NTNR0lEyNjUxBdFKsToIQVMzUyMMQSNTMyN0MaBeMJ2TWVwCkQCKg1SZm5qam8JVwwRNzE3N0QXNTC0sISpjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"P-Col" = _t, #"C-Col" = _t, #"CC-Col" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"P-Col", Int64.Type}, {"C-Col", Int64.Type}, {"CC-Col", type text}}),
    #"Insert List" = Table.TransformColumns(#"Changed Type",{{"CC-Col", each if _ = "list" then {75575,74757,65895} else _}}),
    #"Blank to null" = Table.TransformColumns(#"Insert List",{{"CC-Col", each if Value.Is(_, type list) then _ else null}}),
    #"Expanded CC-Col" = Table.ExpandListColumn(#"Blank to null", "CC-Col")
in
     #"Expanded CC-Col"

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors