Skip to content

Instantly share code, notes, and snippets.

@Medohh2120
Created February 5, 2026 19:44
Show Gist options
  • Select an option

  • Save Medohh2120/9610b17648da284b174e43c961a85cdc to your computer and use it in GitHub Desktop.

Select an option

Save Medohh2120/9610b17648da284b174e43c961a85cdc to your computer and use it in GitHub Desktop.
Repeats a data range based on a frequency column
/*
Name: REPEAT
Recommended version: v2024 or 365
Description: Repeats a data range based on a frequency column.
Optimized with Binary Search.
Made By: Medohh2120
*/
Repeat = LAMBDA(Values,Number_times,
LET(
RunTotal, SCAN(0, Number_times, LAMBDA(acc, nxt, acc + nxt)), //alternative: helper column or SUBTOTAL(9, OFFSET(Number_times, 0, 0, SEQUENCE(ROWS(Number_times)))),
TotalRows, SUM(Number_times),
RowMap, XLOOKUP(SEQUENCE(TotalRows), RunTotal, SEQUENCE(ROWS(Values)), , 1, 2),
CHOOSEROWS(Values, RowMap) //alternative: INDEX(Values, RowMap, SEQUENCE(, COLUMNS(Values)))
)
);
@Medohh2120
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment