Skip to content

Instantly share code, notes, and snippets.

@ImkeF
Created July 4, 2018 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImkeF/2198118707e41dc5d801dd1d2415a172 to your computer and use it in GitHub Desktop.
Save ImkeF/2198118707e41dc5d801dd1d2415a172 to your computer and use it in GitHub Desktop.
let func =
(Table as table, MyFunction as function) =>
let
OldColumnNames = Table.ColumnNames(Table),
NewColumnNames = List.Transform(OldColumnNames, MyFunction),
RenameList = List.Zip({OldColumnNames, NewColumnNames}),
RenameColumns = Table.RenameColumns(Table, RenameList)
in
RenameColumns ,
documentation = [
Documentation.Name = " Table.RenameColumnsWithFunction ",
Documentation.Description = " Returns a <code>Table</code> with the column names transformed according to <code>MyFunction</code> from the 2nd parameter ",
Documentation.LongDescription = " Returns a <code>Table</code> with the column names transformed according to <code>MyFunction</code> from the 2nd parameter ",
Documentation.Category = " Table ",
Documentation.Source = " ",
Documentation.Version = " 1.0 ",
Documentation.Author = " Imke Feldmann: www.TheBIccountant.com . ",
Documentation.Examples = {[Description = " see this blogpost: https://wp.me/p6lgsG-UZ ",
Code = " let
Table = #table( {""TABLENAME.FirstColumn"", ""TABLENAME.SecondColumn""}, { {""A"" ,""B""} } ),
FunctionCall = fnTableRenameColumnsFunction(Table, each Text.Replace(_, ""TABLENAME."", """"))
in
FunctionCall ",
Result = " #table( {""FirstColumn"", ""SecondColumn""}, { {""A"" ,""B""} } ) "]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment