PQ Easiest Way to Set Table2 Column Types equal to Table1?

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have two tables, Table1 and Table2, and I want to set all of the column types of Table2 the same as Table1. All columns will be the same. What's the easiest way to do this? I was thinking of something with Value.Type(Table1) but I'm not sure how to use that in Table2.

Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,
Yes that's right, you should to use Value.Type to get the type of Table1.

The full syntax to replace the table type is:
Code:
= Value.ReplaceType( [B]Table2[/B], Value.Type( Table1 ) )

or replace Table2 by the name of the previous step if part of a query.

Regards
Owen
 
Upvote 0
Hi,
Yes that's right, you should to use Value.Type to get the type of Table1.

The full syntax to replace the table type is:
Code:
= Value.ReplaceType( [B]Table2[/B], Value.Type( Table1 ) )

or replace Table2 by the name of the previous step if part of a query.

Regards
Owen

Thanks - Value.ReplaceType is what I was missing.

One thing though - if Table1 has a column with type date, that column in Table2 becomes type datetime, which isn't really what I would want when the data gets returned to Excel. Not a huge issue but if there were a way to ensure the types were identical it would be ideal.
 
Last edited:
Upvote 0
Hmm...I can see that using Value.ReplaceType may change the table's type, but the values in any given column do not automatically adjust to that type. Is that the problem you are seeing?
For example, a column of integers representing date serial numbers would not appear as dates even if I used Value.ReplaceType with a table type that had that column as a date column.

Maybe there's no getting around changing the types of the values in the columns...
You could use some combination of Value.Type, Type.TableColumn and Table.TransformColumnTypes.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top