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
Anonymous
Not applicable

Create N tables with a function Power Query M

Hi all, 

I have a list of list like this:

caterinafalchi_0-1599124621971.png

Each list is composed by a table and a string, like this:

caterinafalchi_1-1599124664769.png

I want to write an M function that, for each list of the first photo, create a new table in the data model and give her name like the string in the list. For example, with the list above i want to create the new table with name "AZIENDA_GERARCHIA_010". I loop on each list with this code that is working fine:

    Output = List.Transform(ListOfTables , each createTable(_))

The code of my createTable function is:

createTable = (l as list) => (
    let
        tableHierarchy = l{0},
        nameTableHierarchy = l{1},
        newTable = Table.FromRecords(Table.ToRecords(tableHierarchy))
    in

        newTable

)

 

But when i call createTable function, it create a new Source in the scope of the script! Not in my Data Model on Power Bi!

Instead, if i call createTable from button "Invoke", it creates a new table in the Data Model for each time i press on "Invoke".

My questions are: 

  1. How can i create a new table in the Data Model?
  2. How can i rename the table dinamically with the name i want to give her?
6 REPLIES 6
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

I think there is no possibility to create with one query more tables, because one query can only have one result in form of a table. Also there is no possibility to change the query name within M

 

All the best

 

Jimmy

Anonymous
Not applicable

if you gave us some details of the situation you have to manage, we could look for some workaround, like this where you have a list of tables and you can refer to them by name through the key field of a record.
 
[although, I'm sure, it's a solution you could very well come up with on your own]
 
 

 

let
    manyTabs = List.Transform({1..9}, each Table.FromValue(_)),
    manyNames=List.Transform({"1".."9"}, each "tab"&_)
in
    Record.FromList(manyTabs,manyNames)

 

 

 

image.png

Anonymous
Not applicable

@Anonymous  I don't understand the solution, can you show me the content of the table tabs?

Anonymous
Not applicable

image.png

 

 

I don't know if this is a solution of your problem.

It is only a record having a list of key and as correnspondent values a list of tables.

 

 

Anonymous
Not applicable

@Jimmy801 ok but why when i call the same function with the button invoke it creates a new table?

Anonymous
Not applicable

just a guess, 

 

may be this

Function.Invoke(function as function, args as list) as any 

could makes what you want

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.

Top Solution Authors
Top Kudoed Authors