locked
Changing Table Headers to {"Column1", "Column2"} RRS feed

  • Question

  • Is there an easier way to change a table's headers to {"Column1", "Column2"} than this? ...

    Table.Skip( Table.DemoteHeaders( table1 ), 1)

    Thursday, May 14, 2015 5:06 PM

Answers

  • Table.FromRows(Table.ToRows(Table.FromRecords({[A=1,B=2]})))
    • Marked as answer by Mark Weisman Friday, May 15, 2015 1:12 PM
    Thursday, May 14, 2015 11:13 PM

All replies

  • Hi Mark,

    This is not easiest way but dynamic way.

    let
        Source = Excel.CurrentWorkbook(){[Name="Tabela7"]}[Content],
        OldNewHeaders = Table.ToRows(Table.FromColumns({Table.ColumnNames(Source),List.Transform({1..List.Count(Table.ColumnNames(Source))}, each "Column"&Number.ToText(_))})),
        ChangeHeaders = Table.RenameColumns(Source,OldNewHeaders)
    in
        ChangeHeaders

    Regards

    Thursday, May 14, 2015 8:06 PM
  • Table.FromRows(Table.ToRows(Table.FromRecords({[A=1,B=2]})))
    • Marked as answer by Mark Weisman Friday, May 15, 2015 1:12 PM
    Thursday, May 14, 2015 11:13 PM
  • Hi Curt :-)

    I know and sometimes I use the short solution you propose but there is one important note about it. We lose our column data types :-(. This is the only reason I proposed my way. (we do not lose column types).
    Regards :-)

    Monday, May 18, 2015 9:48 AM
  • Bill, in my case I don't care if I lose the column data types, and I don't care about determining or preserving the column names being passed to my user-defined function.
    Monday, May 18, 2015 12:17 PM