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

Return a list of data types the current table has

Hi everyone,

 

After doing a conditional replace using Table.Replace function of some columns in my table, the data types of all the columns have changed to Any. I would love to be able to re-apply the same data types prior to doing a Table.Replace without manually doing so. I can think of getting a list of the used data types per column but I don't know what function to use. 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
3 REPLIES 3
danextian
Super User
Super User

Hi @v-yuta-msft,
I've figured out how to do this. The simple solution is to use Table.Schema function which will return the schema of  a table.  So entering Table.Schema(TablaName)[TypeName] , I could get a list containing the column data types of the table.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
v-yuta-msft
Community Support
Community Support

Hi danextian,

 

To achieve your requirement, you can custom a new function named Table.recovertype like below:

 

Table.recovertype = (t as table) as table => Table.TransformColumnTypes(t,{{"Column1", type Column1_type}, {"Column2", type Column2_type},{},{},{},…………})

 

Every time when you want to recover data type, you can create a new step and invoke the custom function:

#"Recover Type" = Table.recovertype(#"Previous Step")

 

1.PNG

You can refer to PBIX file here:

https://www.dropbox.com/s/itmtdl7yybt1w59/For%20danextian.pbix?dl=0

 

Regards,

Jimmy Tao

Hi @v-yuta-msft

 

Thanks for the reply but what I am trying to achieve is getting the column data type without actually having to manually input them. Your custom function script indicates the actual column type of each column in the table instead of the custom function itself to detect the data types. 

 

The script is  going to be  similar with this: Type.TableColumn(tableType as type, column as text) as type

which will loop through all the columns in the table and return a list that contains the actual data type of each column.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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.