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
rashidanwar
Advocate II
Advocate II

Power Query custom function to loop over multiple tables and do the required transformation

Hi Everyone,

I have multiple tables (Around 10) in Power Query and I want to do some transformation to all the Tables. Say I want to add a custom column to all the tables. 

I want a custom function which when invoked could loop over each table one by one and add the custom column to each table.

Is that even possible in Power Query?

Thanks in advance for any help in this regard.

Rashid

1 ACCEPTED SOLUTION

Yeah, no.  You cannot inject transforms into queries from the outside. You need to do these transforms in each of the queries, or follow my approach and then use references.

View solution in original post

6 REPLIES 6
rashidanwar
Advocate II
Advocate II

Thank you @lbendlin for all the information. 

rashidanwar
Advocate II
Advocate II

Got it @lbendlin . If I follow your approach, then I will have a list of tranformed tables or a  table containing 3 rows, each row referencing to a tranformed table. Can I extract each table as seprate table?

Not in Power BI. Maybe in Excel. Maybe via the Graph API 

rashidanwar
Advocate II
Advocate II

@lbendlin, thank you for the response! 
Yes, I know that we can iterate over rows of table and each row could refer to a table, but my scenario is little different.

I have a key column in all the tables which I want to convert to a primary key column using Add.Key() funtcion.

So I have 
Table1 
Table2
Table3
in Power Query.

I want to create a custom function, that could iterate over each individual table and perform the Table.AddKey(table, "Key", true). In other word this would be added a last tranformation step in each tables' APPLIED STEPS pane.

You can suggest any other better approach. Please note that I have separate tables and after the above transformation I still want them seprate.

Thank you!

Yeah, no.  You cannot inject transforms into queries from the outside. You need to do these transforms in each of the queries, or follow my approach and then use references.

lbendlin
Super User
Super User

yes, that is possible, and it is standard procedure in Power Query, Actions usually iterate over the rows of a table (which can reference your tables).

 

What do you want to do after you modified the tables?

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