Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created January 26, 2024 18:51
Show Gist options
  • Select an option

  • Save cbaragao/3ebb5ffc36240396f1465ebfeae5e59f to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/3ebb5ffc36240396f1465ebfeae5e59f to your computer and use it in GitHub Desktop.
(tbl as table, col_name as text, index_name as text)=>
let
removed_cols = Table.SelectColumns(tbl,{col_name}),
dedupe = Table.Distinct(removed_cols),
sorted = Table.Sort(dedupe,{{col_name, Order.Ascending}}),
add_index = Table.AddIndexColumn(sorted, index_name, 1, 1, Int64.Type),
order = Table.ReorderColumns(add_index,{index_name, col_name})
in
order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment