Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created February 1, 2024 19:32
Show Gist options
  • Select an option

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

Select an option

Save cbaragao/bd0749cc7f3be8fbe496b36b2a715ee9 to your computer and use it in GitHub Desktop.
(batch as number, total as number, base as number) =>
let
batches = List.Generate(
()=>[
from = base,
to = batch
],
each [to] <= total,
each [
from = [from]+batch,
to = if base = 1 then [to] + batch else ([from]+(batch)*2)-1
]
),
to_table = Table.FromList(batches, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
expanded = Table.ExpandRecordColumn(to_table, "Column1", {"from", "to"}, {"from", "to"}),
changed_type = Table.TransformColumnTypes(expanded,{{"from", Int64.Type}, {"to", Int64.Type}}),
index = Table.AddIndexColumn(changed_type, "run", 1, 1, Int64.Type),
reorder = Table.ReorderColumns(index,{"run", "from", "to"})
in
reorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment