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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors