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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Kish1999
Helper II
Helper II

How to populate parent values in the child key

Hello All,

 

I have requirement where i have 2 levels of hierarchy as shown below:

KeyParentContainer
   
11A
21 
31 
41 
55B
65 
75 
85 

 

The requirement is to get the value of container field populated in all the child keys. This will help me roll up the total hours in the hour table which stores hours for each key, but i have show the hours for each container. Can you please help me achieve this. I tried doing some merges and getting the value but was not able to get this.

 

Regards

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWNHpVidaCUjKE8BzDNG4Zmg8EyBLBB2AvPMoDyInDkKzwLBiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Parent = _t, Container = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Parent", Int64.Type}, {"Container", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Container],(k)=> if k[Container]>" " then k[Container] else Table.SelectRows(#"Changed Type",each [Key]=k[Parent]){0}[Container],Replacer.ReplaceValue,{"Container"})
in
    #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWNHpVidaCUjKE8BzDNG4Zmg8EyBLBB2AvPMoDyInDkKzwLBiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Parent = _t, Container = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Parent", Int64.Type}, {"Container", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Container],(k)=> if k[Container]>" " then k[Container] else Table.SelectRows(#"Changed Type",each [Key]=k[Parent]){0}[Container],Replacer.ReplaceValue,{"Container"})
in
    #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.