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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Invoke Custom Function fails when using Table.ExpandTableColumn in the function

I have a custom function that takes a table and expands it using the Table.ExpandTableColumn() function. 

cfrazier_0-1678401598881.png

 

If I invoke it manually it successully runs, but if I call it from within a query I get this response and error.

cfrazier_1-1678401800854.png

The error reads

cfrazier_2-1678401902190.png


The first thing I did was find out which "Data" it was referring to and it pointed to the "Data" in the Table.ExpandTable Columns function inside the query. I've tried everything I can think of to get to work including feeding it my previous table name which gave me a table, but not the data results needed.  Ex: fx1ATTRhdr(#"Removed Top Rows")).

Any ideas where things may be going wrong or what it's looking for once it's inside the function? Any help or directions's appreciated.

2 REPLIES 2
Anonymous
Not applicable

Try changing your function to

 

(MTData as table) =>

let

BaseHeaders = Table.ExpandTableColumn(#"Removed Top Rows", "fx1ATTThdr", each fx1ATTRhdr([Data]))

in 

BaseHeaders

 

--Nate

Anonymous
Not applicable

Hi Nate , thanks for responding with a solution. I may be implementing your solution incorrectly, but it's giving me an error. It doesn't recognize #"Removed Top Rows", which would be located in the query calling this function.
I cut off my full BaseHeaders thats located inside the function. But it looks like this and using MTdata parameter defined as the table I'm trying to bring in from the query, process and return the result.


BaseHeaders = Table.ExpandTableColumn(MTdata, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22", "Column23", "Column24", "Column25", "Column26", "Column27", "Column28", "Column29", "Column30", "Column31", "Date"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22", "Column23", "Column24", "Column25", "Column26", "Column27", "Column28", "Column29", "Column30", "Column31", "Date"})

 

Just to note again, the function functions if I manually run it. It's calling it from a query with the Add Column (Invoke Custom function) that it fails to find "Data". I confirmed its getting into the function but failing on that ExpandTableColumn line, on both of our lines.

I may very well be misreading your solution, but since I'm making this change from within the Custom Function, that would mean this line would be calling on itself (each fxATTRhdr([Data]). Maybe that's possible. I'm still learning and getting my eyes opened to the things that are possible with M Code. I'm just trying to trace and understand the logic.

Any additional clarity would be appreciated Nate. THanks again!

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.