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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
42
Regular Visitor

How to create a parent child hierarchy using PATH when having data quality issues

Hello,

 

I'm new to Power BI and making queries so I hope I can get some help here.

 

I want to visualize data from Azure DevOps in power bi. To do so I have created an analytics view in DevOps which I then connect to using online services. The data I want to visualize are work items that is ordered hierarchically in Azure DevOps. 

 

After some searching I found that using the PATH function seems to be the best way to recreate this parent child hierarchy in Power BI. In case anyone has a better suggestion than using PATH, please let me know 🙂 

 

But when I use the path function i run into problems that seems to be due to poor data quality in the DevOps data. I.e. "parent work items" doesn't exist as own "work items", see below:

 

path error.PNG

Now, since I export all work items from DevOps I find it strange why this error even happen, but after spending a few hours trying to troubleshoot the export view from DevOps I would now rather have a solution to take care of the issue on Power BI side.

 

So the solution I'm looking for now is that in case a parent work item doesn't exist as its own work item, I would either rather empty the parent work item column or create a new work item just so that I can use the path functionality and then continue to build up the parent child hierarchy in Power BI....

 

Please help a rookie 🙂

2 ACCEPTED SOLUTIONS
42
Regular Visitor

Hello again,

 

I found the solution myself so in case anyone would be interested for the future, here it is.

 

I used a two-step approach which is higlighted below:

 

1. In the Power Query editor I created a new column called Parent Path in to which I copied the  Parent Work Item IDs that had a matching Work Item ID-row. I also ensured that these columns were of the same type so that the path- formula later used in the next step would work.

 

let
    Source = Excel.Workbook(File.Contents("\\..Data\Desktop\path-powerBI.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Parent Path" = Table.AddColumn(#"Promoted Headers", "Parent Path", each if List.Contains(#"Promoted Headers"[Work Item Id], [Parent Work Item Id]) then [Parent Work Item Id] else null),
    #"Changed Type" = Table.TransformColumnTypes(#"Parent Path",{{"Work Item Id", Int64.Type}, {"Title", type text}, {"Parent Work Item Id", Int64.Type}, {"Parent Path", Int64.Type}})
in
    #"Changed Type"

 

2. The second step was then to in the modeling in Power BI add a column and populate it using the path-formula referencing the original Work Item Id column and the new Parent Path column.

 

 

 

View solution in original post

42
Regular Visitor

Hello again,

I found the solution myself so in case anyone would be interested for the future, here it is. I used a two-step approach:

 

1. In the Power Query editor I created a new column called Parent Path in to which I copied the Parent Work Item IDs that had a matching Work Item ID-row. I also ensured that these columns were of the same type so that the path- formula later used in the next step would work.

 

let

Source = Excel.Workbook(File.Contents("\\..Data\Desktop\path-powerBI.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],

#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),

#"Parent Path" = Table.AddColumn(#"Promoted Headers", "Parent Path", each if List.Contains(#"Promoted Headers"[Work Item Id], [Parent Work Item Id]) then [Parent Work Item Id] else null),

#"Changed Type" = Table.TransformColumnTypes(#"Parent Path",{{"Work Item Id", Int64.Type}, {"Title", type text}, {"Parent Work Item Id", Int64.Type}, {"Parent Path", Int64.Type}})

in

#"Changed Type"

 

2. The second step was then to in the modeling in Power BI add a column and populate it using the path-formula

Path = PATH(Sheet1[Work Item Id];Sheet1[Parent Path])

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Sample data would help tremendously. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Here are some example data and snapshots illustrating the problem:

First a one illustrating the issue. The problem is with Work Item ID = 34

failed.PNG

 

Then an example of when it works (I have removed Work Item ID = 34)

success.PNG

 

And last the example data used:

Work Item IdTitleParent Work Item Id
11A 
12B 
13C 
211A111
212A211
221B112
222B212
231C113
232C213
31D211
32E222
33F231
34G500
41H211
42I221
43J232
mvsk1987
Frequent Visitor

i have a similar data set to the above but in my case its employees and managers. in the data set which is being used by the report not every manager will be presented as an employee as its a subset of data being used from an excel. so removing the row is not an option . how do i handle that ? i am creating the path as i need to use a dynamic RLS for the manager to be able to see his/her direct and indirect reportees and his own record if it exists.

42
Regular Visitor

Hello again,

I found the solution myself so in case anyone would be interested for the future, here it is. I used a two-step approach:

 

1. In the Power Query editor I created a new column called Parent Path in to which I copied the Parent Work Item IDs that had a matching Work Item ID-row. I also ensured that these columns were of the same type so that the path- formula later used in the next step would work.

 

let

Source = Excel.Workbook(File.Contents("\\..Data\Desktop\path-powerBI.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],

#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),

#"Parent Path" = Table.AddColumn(#"Promoted Headers", "Parent Path", each if List.Contains(#"Promoted Headers"[Work Item Id], [Parent Work Item Id]) then [Parent Work Item Id] else null),

#"Changed Type" = Table.TransformColumnTypes(#"Parent Path",{{"Work Item Id", Int64.Type}, {"Title", type text}, {"Parent Work Item Id", Int64.Type}, {"Parent Path", Int64.Type}})

in

#"Changed Type"

 

2. The second step was then to in the modeling in Power BI add a column and populate it using the path-formula

Path = PATH(Sheet1[Work Item Id];Sheet1[Parent Path])

42
Regular Visitor

Hello again,

 

I found the solution myself so in case anyone would be interested for the future, here it is.

 

I used a two-step approach which is higlighted below:

 

1. In the Power Query editor I created a new column called Parent Path in to which I copied the  Parent Work Item IDs that had a matching Work Item ID-row. I also ensured that these columns were of the same type so that the path- formula later used in the next step would work.

 

let
    Source = Excel.Workbook(File.Contents("\\..Data\Desktop\path-powerBI.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Parent Path" = Table.AddColumn(#"Promoted Headers", "Parent Path", each if List.Contains(#"Promoted Headers"[Work Item Id], [Parent Work Item Id]) then [Parent Work Item Id] else null),
    #"Changed Type" = Table.TransformColumnTypes(#"Parent Path",{{"Work Item Id", Int64.Type}, {"Title", type text}, {"Parent Work Item Id", Int64.Type}, {"Parent Path", Int64.Type}})
in
    #"Changed Type"

 

2. The second step was then to in the modeling in Power BI add a column and populate it using the path-formula referencing the original Work Item Id column and the new Parent Path column.

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors