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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Vinxsta
Frequent Visitor

Creating a Parent ID Key from a flattened table

I have a table as shown below which shows a organisation hierarchy. I'm trying to create a organisation chart but can't do that with the way my data stands at the moment. After some research I found that I would need to create a Parent ID key and then use PATH etc. Please could you advise how i can create a Parent ID key and then what i would need to do to structure my data in the right way so i can use the heriarchy visuals in Power BI, including the dax measures I need to add after. Many thanks in advance!!

 

EmpNameLevel1_mgrLevel2_mgrLevel3_mgrLevel4_mgrLevel5_mgrLevel6_mgr
JohnKevinLionelMindyNeveOscarPaulina
JennyKennyLindaMaggieNiallOlliePatrick
JamesKimLottieMaxNellyOdiPaul
1 ACCEPTED SOLUTION

All you need is an employee table that lists the manager for each employee.

View solution in original post

7 REPLIES 7
HarishKM
Impactful Individual
Impactful Individual

  Hello,
Kindly refer below documentation.Understanding functions for parent-child hierarchies in DAX - DAX | Microsoft Learn

 

 

Thanks 

Harish M

 

Did I answer your question? Mark my post as a solution!

@Vinxsta

Ashish_Mathur
Super User
Super User

Hi,

Show the expected result in a simple Table format.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

Essentially, I want something that looks like the table below. With the current format I'm struggling to use any of the heirarchy visuals to correctly create my org chart.

EmpIDEmpNameManagerIDPath
1CEO11
2Paulina21|2
3Patrick21|3
4Paul21|4
5Oscar31|2|5
6Ollie31|3|6
7Odi31|4|7
8Neve41|2|5|8
9Niall41|3|6|9
10Nelly41|4|7|10
11Mindy51|2|5|8|11
12Maggie51|3|6|9|12
13Max51|4|7|10|13
14Lionel61|2|5|8|11|14
15Linda61|3|6|9|12|15
16Lottie61|4|7|10|13|16
17Kevin71|2|5|8|11|14|17
18Kenny71|3|6|9|12|15|18
19Kim71|4|7|10|13|16|19
20John81|2|5|8|11|14|17|20
21Jenny81|3|6|9|12|15|18|21
22James81|4|7|10|13|16|19|22

All you need is an employee table that lists the manager for each employee.

Vinxsta
Frequent Visitor

Hi Ibendlin, thanks for doing this. I've changed the source but at the last step I'm getting an error at the last step. The table i pasted in my original comment is not the table of my original source but I've amended the column headers and that was fine. Not sure why I'm geting errors

Vinxsta_0-1713536534166.png

 

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

lbendlin
Super User
Super User

I hope this is not how your actual data looks like. However if it does then you can simple brute force the Path construction.

 

lbendlin_0-1713531249763.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Lc1LDoUwCEDRvTB2Jf7q3HRAlPiISBOtRncv1De6bcKBcYQ6/RQqaOhib8tJSezRsc6PtaeLLOGYcLcOeAorQqyMkupT7NfWCDrFZWFHPaP4riBS/gPmnaf1w7jR4Zg3pynnMtLhXY6K+MYw8/8mxPgC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EmpName = _t, Level1_mgr = _t, Level2_mgr = _t, Level3_mgr = _t, Level4_mgr = _t, Level5_mgr = _t, Level6_mgr = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Path", each #table({"path"},{
    {[Level6_mgr] & "|" & [Level5_mgr] & "|" & [Level4_mgr] & "|" & [Level3_mgr] & "|" & [Level2_mgr] & "|" & [Level1_mgr] & "|" & [EmpName]},
    {[Level6_mgr] & "|" & [Level5_mgr] & "|" & [Level4_mgr] & "|" & [Level3_mgr] & "|" & [Level2_mgr] & "|" & [Level1_mgr]},
    {[Level6_mgr] & "|" & [Level5_mgr] & "|" & [Level4_mgr] & "|" & [Level3_mgr] & "|" & [Level2_mgr]},
    {[Level6_mgr] & "|" & [Level5_mgr] & "|" & [Level4_mgr] & "|" & [Level3_mgr]},
    {[Level6_mgr] & "|" & [Level5_mgr] & "|" & [Level4_mgr]},
    {[Level6_mgr] & "|" & [Level5_mgr]},
    {[Level6_mgr]}})),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Path"}),
    #"Expanded Path" = Table.ExpandTableColumn(#"Removed Other Columns", "Path", {"path"}, {"path.1"})
in
    #"Expanded Path"

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". Once you examined the code, replace the Source step with your own source.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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