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
saydu338
New Member

retrieve data based on field

CLIENT IDPARENT IDCLIENT COUNTRYPARENT COUNTRY (New Column)
12345678UKFR
5678nullFRnull
91015678ITAFR

 

Hello,

 

Hope that you can help out here, as I could not find answer online.

 

As you can see certain of my client ID have parent ID, I would like to create a new column as presented above that can find me the country location of the parent. I would like to do this by adding a custom column in power query.

 

hope the table is self explanatory,

 

Thank you

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @saydu338 

Is any answer helpful?

If it is sloved, could you kindly accept it as a solution to close this case and help the other members find it more quickly?
If not, please feel free to let me know.
To get a better performance, could you accept a calculated column/measure using DAX outside the power query?
 
Best Regards
Maggie
edhans
Community Champion
Community Champion

Try this code. It returns the following data:

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUTI1M7cAUqHeSrE60TBeXmlODpByCwILWhoaGCJUeoY4KsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"CLIENT ID" = _t, #"PARENT ID" = _t, #"CLIENT COUNTRY" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CLIENT ID", Int64.Type}, {"PARENT ID", Int64.Type}, {"CLIENT COUNTRY", type text}}),
    #"Added Parent Country" = 
        Table.AddColumn(
            #"Changed Type",
            "Parent Country",
            each
            let
                varParentID = [PARENT ID]
            in
                try Table.SelectRows(
                        #"Changed Type", 
                        each [CLIENT ID] = varParentID)[CLIENT COUNTRY]{0}
                otherwise null,
                type text
        )
        
in
    #"Added Parent Country"

 

2020-06-04 14_36_41-Untitled - Power Query Editor.png 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks @edhans it works, however I can't load the data it takes too long because I have 250000 rows.

6C70E360-F87B-46D6-B115-15282F2171B1_1_201_a.jpeg

is there a way to make it slower ?

 

thanks again

edhans
Community Champion
Community Champion

Try this method @saydu338 - I joined the table with itself.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUTI1M7cAUqHeSrE60TBeXmlODpByCwILWhoaGCJUeoY4KsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"CLIENT ID" = _t, #"PARENT ID" = _t, #"CLIENT COUNTRY" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CLIENT ID", Int64.Type}, {"PARENT ID", Int64.Type}, {"CLIENT COUNTRY", type text}}),
    #"Self Join" = Table.NestedJoin(#"Changed Type", {"PARENT ID"}, #"Changed Type", {"CLIENT ID"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Self Join", "Changed Type", {"CLIENT COUNTRY"}, {"Parent Country"})
in
    #"Expanded Changed Type"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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