Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created June 10, 2023 14:13
Show Gist options
  • Select an option

  • Save ncalm/05e1561d8aac52f27cc3e619246e40db to your computer and use it in GitHub Desktop.

Select an option

Save ncalm/05e1561d8aac52f27cc3e619246e40db to your computer and use it in GitHub Desktop.
This Power Query function handles headers which have been split onto multiple rows
(Source as table, header_condition as function) as any =>
let
// two row header
hh = Table.SelectRows(Source, header_condition) ,
// list of new column headers
h = List.Accumulate(
Table.ToColumns(hh),
{},
(a,b) => List.Combine({a,{Text.Combine(b," ")}})
),
// get the data records (without the two header rows)
data = Table.FromRecords(List.Difference(Table.ToRecords(Source),Table.ToRecords(hh))),
renames = List.Zip({Table.ColumnNames(data),h}),
// use the new header rows
tbl = Table.RenameColumns(data, renames),
result = tbl
in
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment