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
richardnlove918
Frequent Visitor

Power Query: Make a Record containing Tables using M

Hi all,

 

I am looking to create a record containing tables.  I can do this by hardcoding table names in the query ...

 

2019-03-31_13-48-02.png

 

.... but I'm looking to do this using M providing as input a table/column of table names:

 

2019-03-31_13-48-14.png

 

I've tried Record.FromList and other combinations but am stuck.

 

Thank you,

Richard

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @richardnlove918 ,

You could create a custom column with the formula below.

= Table.AddColumn(#"Changed Type", "Value", each Expression.Evaluate("Table1",#shared) )

Here is the output.

Capture.PNG

Best  Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-piga-msft  there is a mole in this solution, you cannot use this if the table name has spaces in it eg: Student Details. it shows error in that case.

how can we correct that.

OwenAuger
Super User
Super User

Hi @richardnlove918 

If you construct a table that has a "Name" column (containing desired field names) and a "Value" column (containing desired field values) you can then use Record.FromTable to convert the table to a record.

 

The below code should work assuming you have existing queries called table1, table2 & table3.

It first creates a table with a Name column containing the required table names, then uses Expression.Evaluate to add a column containing the table corresponding to the text value in the Name column.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKklMykk1VIrVgTKNEExjpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
    AddValueColumn = Table.AddColumn(#"Changed Type", "Value", each Expression.Evaluate([Name], #shared), type table),
    ConvertToRecord = Record.FromTable(AddValueColumn)
in
    ConvertToRecord

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.