メインコンテンツまでスキップ

Table.TransformColumns

1 つ以上の列の値を変換します。

Syntax

Table.TransformColumns(
table as table,
transformOperations as list,
optional defaultTransformation as function,
optional missingField as MissingField.Type
) as table

Remarks

transformOperations に一覧表示されている各列操作を適用して table を変換します (形式は { column name, transformation } または { column name, transformation, new column type })。 defaultTransformation を指定すると、transformOperations に一覧表示されていないすべての列に適用されます。 transformOperations に一覧表示されている列が存在しない場合は、省略可能なパラメーター missingField が代替を指定しない限り、例外がスローされます (例: MissingField.UseNull または MissingField.Ignore)。

Examples

Example #1

列 [A] のテキスト値を数値に変換し、列 [B] の数値をテキスト値に変換します。

Table.TransformColumns(
Table.FromRecords({
[A = "1", B = 2],
[A = "5", B = 10]
}),
{
{"A", Number.FromText},
{"B", Text.From}
}
)

Result:

Table.FromRecords({
[A = 1, B = "2"],
[A = 5, B = "10"]
})

Example #2

存在しない列 [X] の数値をテキスト値に変換します。存在しない列は無視されます。

Table.TransformColumns(
Table.FromRecords({
[A = "1", B = 2],
[A = "5", B = 10]
}),
{"X", Number.FromText},
null,
MissingField.Ignore
)

Result:

Table.FromRecords({
[A = "1", B = 2],
[A = "5", B = 10]
})

Example #3

存在しない列 [X] の数値をテキスト値に変換します。存在しない列には既定で NULL が設定されます。

Table.TransformColumns(
Table.FromRecords({
[A = "1", B = 2],
[A = "5", B = 10]
}),
{"X", Number.FromText},
null,
MissingField.UseNull
)

Result:

Table.FromRecords({
[A = "1", B = 2, X = null],
[A = "5", B = 10, X = null]
})

Example #4

列 [B] 内の数値を増分してテキスト値に変換し、他のすべての列を数値に変換します。

Table.TransformColumns(
Table.FromRecords({
[A = "1", B = 2],
[A = "5", B = 10]
}),
{"B", each Text.From(_ + 1), type text},
Number.FromText
)

Result:

Table.FromRecords({
[A = 1, B = "3"],
[A = 5, B = "11"]
})

Category

Table.Transformation