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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Super User
Super User

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

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?

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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