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 table with dynamically fetched type data

Hello, I have a REST service that gives me data along with type information. Right now I am transforming the type information into a columnHeaders list of {name, type} pairs and creating a table using just #table(columnNames, rows) and then using Table.TransformColumnTypes(table, columnHeaders) to assign it the type data. It seems to be less efficient and more conversion error-prone than creating the table with the type info immediately.

 

Now, I know that I can supply a table type instead of the columnNames list, but I can't find a way to construct it dynamically without using Chris Webb's ugly hack of constructing a table type literal string and evaluating it.

 

Is there a better way? I even tried turning the columnHeaders into a record directly resembling the row-type part of the table type and doing type table myRecord, but that also fails with "cannot convert from type Record to type Type".

2 ACCEPTED SOLUTIONS

Now I get it. 

I'm not aware of an alternative solution to it. 

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

Anonymous
Not applicable

While researching something else I stumbled on a solution - one can create a closed record, easiest way being the Type.ForRecord function, and then do type table (myRecord), which actually works.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

While researching something else I stumbled on a solution - one can create a closed record, easiest way being the Type.ForRecord function, and then do type table (myRecord), which actually works.

ImkeF
Super User
Super User

Hi @Anonymous 

could you please post the link to the "ugly hack" and briefly explain what you'd like to have removed to suit your requirements?

Thanks!

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

Hacky way:
https://blog.crossjoin.co.uk/2018/10/03/function-m-table-type/

Generating an expression via string concatenation and evaluating it from string is basically the definition of an ugly hack, even if done well. I don't mean to detriment Chris' expertise, I am just hoping that there is a power query functionality intended for such basic use case.

Now I get it. 

I'm not aware of an alternative solution to it. 

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

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

I'm still a little confused about your scenario. 

If it is convenient could you share some screeshots and your desired output so that we could understand better.

Hope @ImkeF who is good at M query could have any ideas.

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.

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