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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
THEG72
Helper V
Helper V

Add New Column in M based on Parent

I have a Table of Accounts which has an Account ID and Parent ID. I want to ADD a new Column in the Query Editor for the Parent Name.

 

What code should i use to add the new Parent Name field based on image below? I have the ID's  for both Parent and Acccount (Child). The Account ID will indicate what the Parent's name will be.

New Column for Parent Name based on Account ID shown in Parent ID ColumnNew Column for Parent Name based on Account ID shown in Parent ID Column

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

You can simply use your current table as a lookuptable and use the Parent ID. Your formula would look like so:

 

Table.NestedJoin(#"Removed Other Columns",{"ParentAccountID"},#"Removed Other Columns",{"AccountID"},"Source",JoinKind.LeftOuter)

 

See this little screencast how it works: https://www.youtube.com/watch?v=looCm3cbINw

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
ImkeF
Super User
Super User

You can simply use your current table as a lookuptable and use the Parent ID. Your formula would look like so:

 

Table.NestedJoin(#"Removed Other Columns",{"ParentAccountID"},#"Removed Other Columns",{"AccountID"},"Source",JoinKind.LeftOuter)

 

See this little screencast how it works: https://www.youtube.com/watch?v=looCm3cbINw

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeF

thanks again, the trick to change back to source is truly amazing with M....thanks for help again and the video made it easy!

 

Grouping Parent HeadersGrouping Parent Headers

Here is the final code, i changed the source to my Table Select Columns so i didnt have to reselect the columnns to display

let
    Source = Accounts,
    TableSelect = Table.SelectColumns(Source,{"AccountID", "ParentAccountID", "Account Name", "AccountTypeID", "AccountLevel", "IsTotal"}),
    FitlerTable = Table.SelectRows(TableSelect, each ([AccountTypeID] = "H")),
    #"Merged Queries" = Table.NestedJoin(TableSelect,{"ParentAccountID"},FitlerTable,{"AccountID"},"FitlerTable",JoinKind.LeftOuter),
    #"Expanded FitlerTable" = Table.ExpandTableColumn(#"Merged Queries", "FitlerTable", {"Account Name"}, {"FitlerTable.Account Name"})
in
    #"Expanded FitlerTable"

Hopefully, others will find this useful to group accounts together.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.