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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Richard_Halsall
Helper IV
Helper IV

Name a Table from a Column Value

Hi

 

Is there a way to name a table based on a column value in that table

 

I have a grouped table of data as below named AssetActivity

Richard_Halsall_0-1740739840675.png

In a new query I have this code

 

let
Source = if Table.RowCount(AssetActivity) >= 1 then AssetActivity{0}[AllData] else null,

 

which creates a table named Asset1 with all data from the inner table named 'AllData'

 

I manually create a new query for each row and end up with 26 tables named Asset1.....Asset26

 

Is there anyway I can name the table 'T-33_441' rather than it being names Asset1 i.e. the value in the column named Asset present in the AssetActivity table

 

If it helps the Asset column is also present in the inner table

 

Any help would be appreciated. Thanks

1 ACCEPTED SOLUTION
PwerQueryKees
Super User
Super User

I can not reproduce your behaviour. The code snippet you gave is not complete, so I guess there is more happening.

BUT,

You will always have to manuall create a new query for each row. 
Given that...

Starting with:

PwerQueryKees_0-1740745142957.png

Rightclick on the Table in any line and "Add as New Query

PwerQueryKees_1-1740745252651.png

Will produce this new query:

PwerQueryKees_2-1740745365534.png



Did I answer your question? Then please (also) mark my post as a solution and make it easier to find for others having a similar problem.
Remember: You can mark multiple answers as a solution...
If I helped you, please click on the Thumbs Up to give Kudos.

Kees Stolker

A big fan of Power Query and Excel

 

 

View solution in original post

4 REPLIES 4
PwerQueryKees
Super User
Super User

Still not entirely sure what you want to achieve, but NO, you can not rename a query by code on PowerQuery.

If you are working in Excel, you CAN use VBA to rename queries, but you will not hav access to the query results in VBA...

Kees Stolker

A big fan of Power Query and Excel

PwerQueryKees
Super User
Super User

I can not reproduce your behaviour. The code snippet you gave is not complete, so I guess there is more happening.

BUT,

You will always have to manuall create a new query for each row. 
Given that...

Starting with:

PwerQueryKees_0-1740745142957.png

Rightclick on the Table in any line and "Add as New Query

PwerQueryKees_1-1740745252651.png

Will produce this new query:

PwerQueryKees_2-1740745365534.png



Did I answer your question? Then please (also) mark my post as a solution and make it easier to find for others having a similar problem.
Remember: You can mark multiple answers as a solution...
If I helped you, please click on the Thumbs Up to give Kudos.

Kees Stolker

A big fan of Power Query and Excel

 

 

Hi

So the code I provided allows me to create a new query for each row, what I am trying to achieve, as this file is a template file to be distributed to colleagues, if I create 8 new queries named Query 1, Query 2, Query 3 etc can I rename the query using code to the value in the column named asset

 

e.g. Query 1 renamed to T-16 441 using code

Thanks

Akash_Varuna
Super User
Super User

Hi @Richard_Halsall Could you try this please 

  • Group Data by Asset:

    • Go to Home → Group By.
    • In the Group By window:
      • Group by the Asset column.
      • Operation: All Rows.
  • Create a New Column for Table Names:

    • Add a custom column to extract the Asset value as the table name:
      • Go to Add Column → Custom Column.
      • Use this formula:
        Text.From([Asset])
  • Iterate and Save Tables: For each row (grouped by Asset), you can extract the nested table and save it with the dynamic name. However, Power Query does not directly support exporting multiple tables automatically. You’ll need to:
    • Go to each grouped table.
    • Rename the query manually based on the new column.
      Heres the M code 

 

let
    Source = YourDataTable,
    GroupedData = Table.Group(Source, {"Asset"}, {{"AllData", each _, type table [Column1=type, Column2=type]}}),
    NamedTables = Table.AddColumn(GroupedData, "TableName", each "Table_" & Text.From([Asset])),
    Result = Table.TransformColumns(NamedTables, {"AllData", each Table.RenameColumns(_, {"Asset", "RenamedTable"})})
in
    Result
​

 

If this post helped please do give a kudos and accept this as a solution
Thanks In Advance

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors