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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Matjo
Advocate I
Advocate I

Transform multiple queries at once

Hi, 

I have 60 queries for different tables. I want to apply the function Table.FirstN to all of them. 
I tried selecting all and using the function Keep Rows but it only affected one query. 

Is there an easy way to add an additional step to all of the queries that keeps the first 100 rows.

Best regards,
Mattias

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Yes, trick is to get a "table-view" of all your DB-tables where you can add a column. See how this works for a SQL-DB here:

 

 

The code as a function you can find here: https://gist.github.com/ImkeF/7f4fca8f7a7334d7fe7fb1ec761711da

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

6 REPLIES 6
ImkeF
Community Champion
Community Champion

Yes, trick is to get a "table-view" of all your DB-tables where you can add a column. See how this works for a SQL-DB here:

 

 

The code as a function you can find here: https://gist.github.com/ImkeF/7f4fca8f7a7334d7fe7fb1ec761711da

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks @ImkeF this is great. Is there a way to output the db-tables to different tables in power query? i.e. having one pquery query per db table

ImkeF
Community Champion
Community Champion

Not with this additional transformation, unfortunatly.

The only way to create one query per table is through the steps via the manual UI where you click each table and one query will be created for each of them.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

what if there's no transformation? i.e. is there a way to bring all the tables from the db into different pquery queries?

ImkeF
Community Champion
Community Champion

Yes, if you import from SQL-Server for example, you will be presented a UI like this:

 

image.png

 

for every table or view you check here, a seperate query will be created.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

thanks @ImkeF. what if i don't wanna select them manually? is there a way to write a script that'll do that for me?

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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