You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: query-languages/m/table-transformcolumntypes.md
+97-12Lines changed: 97 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,35 +13,120 @@ Table.TransformColumnTypes(<b>table</b> as table, <b>typeTransformations</b> as
13
13
14
14
## About
15
15
16
-
Returns a table from the input `table` by applying the transform operation to the columns specified in the parameter `typeTransformations` (where format is { column name, type name}), using the specified culture in the optional parameter `culture` (for example, "en-US"). If the column doesn't exist, an exception is thrown.
16
+
Returns a table by applying the transform operations to the specified columns using an optional culture.
17
+
18
+
*`table`: The input table to transform.
19
+
*`typeTransformations`: The type transformations to apply. The format for a single transformation is { column name, type value }. A list of transformations can be used to change the types of more than one column at a time. If a column doesn't exist, an error is raised.
20
+
*`culture`: (Optional) The culture to use when transforming the column types (for example, "en-US").
21
+
22
+
The type value in the `typeTransformations` parameter can be `any`, all of the `number` types, `text`, all of the `date`, `time`, `datetime`, `datetimezone`, and `duration` types, `logical`, or `binary`. The `list`, `record`, `table`, or `function` types aren't valid for this parameter.
17
23
18
24
## Example 1
19
25
20
-
Transform the number values in column [a]to text values from the table `({[a = 1, b = 2], [a = 3, b = 4]})`.
26
+
Transform the number values in the first column to text values.
21
27
22
28
**Usage**
23
29
24
30
```powerquery-m
25
-
Table.TransformColumnTypes(
26
-
Table.FromRecords({
27
-
[a = 1, b = 2],
28
-
[a = 3, b = 4]
31
+
let
32
+
Source = #table(type table [a = number, b = number],
33
+
{
34
+
{1, 2},
35
+
{3, 4}
29
36
}),
30
-
{"a", type text},
31
-
"en-US"
32
-
)
37
+
#"Transform Column" = Table.TransformColumnTypes(
38
+
Source,
39
+
{"a", type text}
40
+
)
41
+
in
42
+
#"Transform Column"
33
43
```
34
44
35
45
**Output**
36
46
37
47
```powerquery-m
38
-
Table.FromRecords({
39
-
[a = "1", b = 2],
40
-
[a = "3", b = 4]
48
+
#table(type table [a = text, b = number],
49
+
{
50
+
{"1", 2},
51
+
{"3", 4}
41
52
})
42
53
```
43
54
55
+
## Example 2
56
+
57
+
Transform the dates in the table to their French text equivalents.
58
+
59
+
**Usage**
60
+
61
+
```powerquery-m
62
+
let
63
+
Source = #table(type table [Company ID = text, Country = text, Date = date],
64
+
{
65
+
{"JS-464", "USA", #date(2024, 3, 24)},
66
+
{"LT-331", "France", #date(2024, 10, 5)},
67
+
{"XE-100", "USA", #date(2024, 5, 21)},
68
+
{"RT-430", "Germany", #date(2024, 1,18)},
69
+
{"LS-005", "France", #date(2023, 12, 31)},
70
+
{"UW-220", "Germany", #date(2024, 2, 25)}
71
+
}),
72
+
#"Transform Column" = Table.TransformColumnTypes(
73
+
Source,
74
+
{"Date", type text},
75
+
"fr-FR"
76
+
)
77
+
in
78
+
#"Transform Column"
79
+
```
80
+
81
+
**Output**
82
+
83
+
```powerquery-m
84
+
#table(type table [Company ID = text, Country = text, Date = text],
85
+
{
86
+
{"JS-464", "USA", "24/03/2024"},
87
+
{"LT-331", "France", "05/10/2024"},
88
+
{"XE-100", "USA", "21/05/2024"},
89
+
{"RT-430", "Germany", "18/01/2024"},
90
+
{"LS-005", "France", "31/12/2023"},
91
+
{"UW-220", "Germany", "25/02/2024"}
92
+
})
93
+
```
94
+
95
+
## Example 3
96
+
97
+
Transform the dates in the table to their German text equivalents, and the values in the table to percentages.
98
+
99
+
**Usage**
100
+
101
+
```powerquery-m
102
+
let
103
+
Source = #table(type table [Date = date, Customer ID = text, Value = number],
0 commit comments