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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

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.

Top Solution Authors