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.
I am importing multiple spreadsheets with different languages, so am having to hardcode my columns names by ordinal position in the M code.
I find the syntax below hard to read and even harder to write....is there a better way of doing this? I've seen a few functions that have been written that deal with column renaming, but I haven't found an understandable article on how one actually writes or incorporates an existing function into a PQ project. Hopefully there's a way to define a function globally so it can be called from all queries?
rename00 = #"Removed Columns1",
rename01 = Table.RenameColumns(rename00,{{Table.ColumnNames(rename00){1}, "CBF ID"}}),
rename02 = Table.RenameColumns(rename01,{{Table.ColumnNames(rename01){2}, "CBF Description"}}),
rename03 = Table.RenameColumns(rename02,{{Table.ColumnNames(rename02){3}, "RTO Recovery TIME Objective"}}),
rename04 = Table.RenameColumns(rename03,{{Table.ColumnNames(rename03){4}, "RPO Recovery POINT Objective"}}),
rename05 = Table.RenameColumns(rename04,{{Table.ColumnNames(rename04){5}, "Overall Business Impact"}}),
rename06 = Table.RenameColumns(rename05,{{Table.ColumnNames(rename05){6}, "Disruption Frequency"}}),
rename07 = Table.RenameColumns(rename06,{{Table.ColumnNames(rename06){7}, "# of FTEs"}}),
rename08 = Table.RenameColumns(rename07,{{Table.ColumnNames(rename07){8}, "Revenue Impact"}}),
rename09 = Table.RenameColumns(rename08,{{Table.ColumnNames(rename08){9}, "Cost Impact"}}),
Solved! Go to Solution.
You could do it all in one step, for example:
Table.RenameColumns(rename00,{ {Table.ColumnNames(rename00){1}, "CBF ID"}, {Table.ColumnNames(rename00){2}, "CBF Description"},
{Table.ColumnNames(rename00){3}, "RTO Recovery TIME Objective"}.... }),
Notice each rename is wrapped in {} and seperated by commas, but then the total step is wrapped in the red {}
Appreciate your Kudos
I love to share - connect with me!
Stay up to date on
Read my blogs on
Did I answer your question? Mark my post as a solution! Proud to be a Super User!
Connect with me!
Stay up to date on
Read my blogs on
You could do it all in one step, for example:
Table.RenameColumns(rename00,{ {Table.ColumnNames(rename00){1}, "CBF ID"}, {Table.ColumnNames(rename00){2}, "CBF Description"},
{Table.ColumnNames(rename00){3}, "RTO Recovery TIME Objective"}.... }),
Notice each rename is wrapped in {} and seperated by commas, but then the total step is wrapped in the red {}
Appreciate your Kudos
I love to share - connect with me!
Stay up to date on
Read my blogs on
Did I answer your question? Mark my post as a solution! Proud to be a Super User!
Connect with me!
Stay up to date on
Read my blogs on
Wonderful, that syntax is much nicer, and you can even write it like the following and it maintains the structure even after you save. Way easier to read and write!!
t = removeHeaderRows, renamedColumns = Table.RenameColumns(t,{ {Table.ColumnNames(t){1}, "Dept Request Num"}, {Table.ColumnNames(t){2}, "Need"}, {Table.ColumnNames(t){3}, "Business Reason"}, {Table.ColumnNames(t){4}, "Requester Name"}, {Table.ColumnNames(t){5}, "Desired Time Frame (months)"}, {Table.ColumnNames(t){6}, "Impact if not completed"}, {Table.ColumnNames(t){7}, "Comments"} }), #"Removed Top Rows" = Table.Skip(renamedColumns,1),
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
81 | |
70 | |
62 |
User | Count |
---|---|
148 | |
116 | |
104 | |
90 | |
65 |