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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
42
Regular Visitor

Performance issue when trying to replicate path function in M

Background

I export work items from Azure DevOps and would like to be able to filter out and load into Power BI only work items that is hierarchically ordered under a specific work item parent.

 

Problem

So in order to achieve the above I am trying to replicate the (DAX) Path function with M and power query. So that I can use the path as input to my filtering in the next step.  I have searched for a solution and found these two alternative ways of replicating the path function with M:

let
    ChangedType = Table.TransformColumnTypes(DevOps_import,{{"Work Item Id", type text}, {"Parent Work Item Id", type text}}),
    NewStep=Table.AddColumn(ChangedType, "Path", each let
    myfunction=(myvalue)=>
                    let
                    mylist=Table.SelectRows(ChangedType,each [Work Item Id]=myvalue)[Parent Work Item Id],
                    result=Text.Combine(mylist)
                    in
                    if result= null or result ="" then "" else if @myfunction(result)=null or @myfunction(result)="" then result else result & "|" & @ myfunction(result)
in
Text.Combine(List.Reverse(List.RemoveItems({[Work Item Id]}&{[Parent Work Item Id]}&Text.Split(myfunction([Parent Work Item Id]),"|"),{"",null})),"|"))
in
    ChangedType

 

or alternatively

 

let
    ChangedType = Table.TransformColumnTypes(DevOps_import,{{"Work Item Id", type text}, {"Parent", type text}}),
     myfunction=(ChildCol,ParentCol,CurrentParent)=>
                    let
                    mylist=Table.Column(Table.SelectRows(ChangedType,each Record.Field(_,ChildCol)=CurrentParent),ParentCol),
                    result=Text.Combine(mylist)
                    in
                  
                    Text.TrimEnd(
                    if result ="" then ""  else @ result & "|" & @ myfunction(ChildCol,ParentCol,result),
                   "|"),                          
    Path=Table.AddColumn(ChangedType,
                            "Path", each
                                    Text.Trim(
                                    Text.Combine(
                                    List.Reverse(
                                        List.RemoveItems(
                                        Text.Split(myfunction("Work Item Id","Parent",[Parent]),"|"),{""}
                                                        )
                                                 )
                                             &{[Parent],[Work Item Id]}
                                             ,
                                             "|"),"|"))
in
    Path
 
The problem is that both alternatives gives huge performance issues and being a newbie at this I don't have the knowledge to solve it myself. The DevOps_import table referenced has around 20 000 rows and is based on a import from Azure DevOps.
 
I'm thinking the solution would be in doing some itermediate buffering or indexing or similar but I have no idea on how to achieve that. Any help would be very much appreciated!
 
1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi @42  

in order to determine the PATH-result you have to read all rows from your source first. So just to be clear that this approach would only help you to load less data into your data model.

Recursion using the @-sign in is said to be slow in Power Query. Using List.Generate on buffered (!) inputs is often much faster. 
Some time ago, I've created a parent-child-function that you can find here: https://gist.githubusercontent.com/ImkeF/3a6b50e705bfbdbcb3480b6be505322a/raw/179e0bd0bced37328e92e5...  (not the best coding style, but has served me well so far...)

 

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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 Kudoed Authors