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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

An error occurred in the ‘Query2’ query. Expression.Error: There is an unknown identifier.

Hi community. I am getting the an error in my Invoked Function. This is the code i used. Thank you!

 

= let 
    funcWithPathItem = (ParChTable as table, ChildKey as text, ParentKey as text, LevelColumnName as text) =>
        let
            SelectRelevantColumns = Table.SelectColumns(ParChTable, {ChildKey, ParentKey, LevelColumnName}),
            #"Changed Type" = Table.TransformColumnTypes(SelectRelevantColumns, {{ChildKey, type text}, {ParentKey, type text}}),
            ReplaceNulls = Table.ReplaceValue(#"Changed Type", null, "", Replacer.ReplaceValue, {ParentKey}),
            MissingParents = List.Buffer(List.Select(List.Difference(List.Distinct(Table.Column(ReplaceNulls, ParentKey)), List.Distinct(Table.Column(ReplaceNulls, ChildKey))), each _ <> "")),
            AddMissingParents = Table.Buffer(Table.Combine({ReplaceNulls, #table({ChildKey, LevelColumnName, ParentKey}, List.Transform(MissingParents, each {_, "Unknown TopLevel" & Text.From(List.PositionOf(MissingParents, _)), ""}))})),
            #"Merged Queries0" = Table.NestedJoin(AddMissingParents, {ChildKey}, AddMissingParents, {ParentKey}, "SelectRelevantColumns", JoinKind.LeftOuter),
            CheckIfIsLeaf = Table.AddColumn(#"Merged Queries0", "IsLeaf", each if Table.IsEmpty([SelectRelevantColumns]) then "yes" else "no"),
            #"Replaced Value1" = Table.ReplaceValue(CheckIfIsLeaf, null, "", Replacer.ReplaceValue, {ParentKey, LevelColumnName}),
            AddStartPath = Table.AddColumn(#"Replaced Value1", "Path", each Text.Trim(Record.Field(_, ChildKey) & "|" & Record.Field(_, ParentKey), "|")),
            #"Duplicated Column" = Table.DuplicateColumn(AddStartPath, LevelColumnName, "FirstName"),
            Feed = Table.DuplicateColumn(#"Duplicated Column", ParentKey, "FirstParentKey"),
            
            // Split hierarchy into levels using PATHITEM()
            SplitIntoLevels = Table.AddColumn(Feed, "LevelPath", 
                List.Transform(
                    Text.Split([Path], "|"), 
                    (x) => if x = "" then null else x
                )
            )
        in
            SplitIntoLevels
in
    funcWithPathItem

 

 

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , What is the objective of (x) => if x = "" then null else x, will only Text.Split will not help ?

 

SplitIntoLevels = Table.TransformColumns(DuplicatedColumn, {"LevelPath", each Text.Split(_, "|"), type list})

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak Thank you for your reply. I managed to invoke the function. However, it is not working as intended... what i wan to achieve is something like the PATHITEM function where the path is split into its specific level. Do you know what i have to change? Thank You! 

Helpful resources

Announcements
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.