Table.TransformColumns
Μετασχηματίζει τις τιμές μίας ή περισσότερων στηλών.
Syntax
Table.TransformColumns(
table as table,
transformOperations as list,
optional defaultTransformation as function,
optional missingField as MissingField.Type
) as table
Remarks
Transforms the specified table by applying each column operation in a list.
table: The table to transform.transformOperations: The transformations to make to the table. The format of this parameter is either { column name, transformation } or { column name, transformation, new column type }.defaultTransformation: (Optional) The default transformation applied to all columns not listed intransformOperations.missingField: (Optional) Specifies the expected action for missing values. If a column listed intransformOperationsdoesn't exist, an error is raised (MissingField.Error) unless this parameter specifies an alternative. Use one of the following values:MissingField.UseNull: Any missing fields are included asnullvalues.MissingField.Ignore: Any missing fields are ignored.
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
Convert the number values in missing column [X] to text values, defaulting to null for columns that don't exist.
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 #3
Αυξήστε τις αριθμητικές τιμές στη στήλη [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"]
})
Example #4
Μετακινήστε τις προγραμματισμένες εργασίες συντήρησης που πραγματοποιούνται ημέρες αργίας στις ΗΠΑ την επόμενη ημέρα ή, εάν η αργία πραγματοποιείται την Παρασκευή, την επόμενη Δευτέρα.
let
MaintenanceSchedule = #table(type table [Task = text, Date = date],
{
{"HVAC Check", #date(2025, 7, 10)}, // Not a holiday
{"Window Washing", #date(2025, 9, 1)}, // Labor Day
{"Fire Drill", #date(2025, 9, 17)}, // Not a holiday
{"Light Replacement", #date(2025, 11, 27)} // Thanksgiving
}),
USHolidays = {
#date(2025, 1, 1), // New Year's Day
#date(2025, 7, 4), // Independence Day
#date(2025, 9, 1), // Labor Day
#date(2025, 11, 27), // Thanksgiving
#date(2025, 12, 25) // Christmas
},
AdjustedSchedule = Table.TransformColumns(
MaintenanceSchedule,
{{"Date", each if List.Contains(USHolidays, _) then
if Date.DayOfWeek(_, Day.Sunday) = 5 then
Date.AddDays(_, 3) // Friday to Monday
else
Date.AddDays(_, 1) // Other to next day
else _, type date}}
)
in
AdjustedSchedule
Result:
#table(type table[Task = text, Date = date],
{
{"HVAC Check", #date(2025, 7, 10)},
{"Window Washing", #date(2025, 9, 2)},
{"Fire Drill", #date(2025, 9, 17)},
{"Light Replacement", #date(2025, 11, 28)}
})
Category
Table.Transformation