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
stvcdms
Frequent Visitor

Custom Function Error

Hello,

 

I am very new to make custom functions, but I am running into an error on the following function. I have an Employee table and want to flatten the employee - manager relationship. Before making it recursive, I just tried to make a single join function. I keep getting and error with how I am trying to pass the coumns to the Table.AddJoinColumn() function.

 

Below is the function and query calling it.

 

fnFlattenHierarchy

 

(HierarchyTable, ChildKeyColumn, ParentKeyColumn) =>
let
Source = Table.AddJoinColumn(HierarchyTable,{"ParentKeyColumn"},()=>HierarchyTable,{"ChildKeyColumn"},"NewColumn")
in

Source

 

 

Flattened Employee Table

 

let
Source = fnFlattenHierarchy(Employees, "EmployeeKey", "ParentEmployeeKey")
in
Source

 

Error

 

[Expresssion.Error] The Column 'ParentKeyColumn' of the table wasn't found.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

 ibeleive that putting double quotes around ParentKeyColumn you are having it be treated as a string instead of a variable.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

 ibeleive that putting double quotes around ParentKeyColumn you are having it be treated as a string instead of a variable.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Well that was easy! Worked like a charm. Hopefully this is an OK approach to making it recursive, thanks for the help!

I have a blog post on recursion with "M". Different problem, but recursion is recursion:

 

https://community.powerbi.com/t5/Community-Blog/Using-Recursion-to-Solve-Hex-to-Decimal-Conversion/b...



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

November Carousel

Fabric Community Update - November 2024

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

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.