smozgur
BatCoder
- Joined
- Feb 28, 2002
- Messages
- 2,659
REPEATBYNUMBER function takes a range (or table) that has the first column as the item name and the last column as the repeat number then returns a new column of rows with the item names repeated by the required number of times. (I learned the main idea from Karina Adcock, and used the TAKE function to make it work with a single range/table parameter).
EDIT: This function assumes that each product in the source data exists in the inventory (Repeat >= 1). For an alternative implementation that considers Repeat = 0 please see @Xlambda's RPTBYNR function below.
EDIT: This function assumes that each product in the source data exists in the inventory (Repeat >= 1). For an alternative implementation that considers Repeat = 0 please see @Xlambda's RPTBYNR function below.
Excel Formula:
=LAMBDA(data,
XLOOKUP(
SEQUENCE(SUM(TAKE(data,,-1))),
VSTACK(1, SCAN(1,TAKE(data,,-1),LAMBDA(a,b,a+b))),
VSTACK(TAKE(data,,1),""),
,
-1
)
)
RepeatByNumber | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | Product | Repeat | Result (range param) | Result (table param) | ||||
2 | Apple | 5 | Apple | Apple | ||||
3 | Banana | 4 | Apple | Apple | ||||
4 | Cherry | 2 | Apple | Apple | ||||
5 | Strawberry | 4 | Apple | Apple | ||||
6 | Apple | Apple | ||||||
7 | Banana | Banana | ||||||
8 | Banana | Banana | ||||||
9 | Banana | Banana | ||||||
10 | Banana | Banana | ||||||
11 | Cherry | Cherry | ||||||
12 | Cherry | Cherry | ||||||
13 | Strawberry | Strawberry | ||||||
14 | Strawberry | Strawberry | ||||||
15 | Strawberry | Strawberry | ||||||
16 | Strawberry | Strawberry | ||||||
Sheet4 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2:D16 | D2 | =REPEATBYNUMBER(A2:B5) |
F2:F16 | F2 | =REPEATBYNUMBER(ProductTable) |
Dynamic array formulas. |
Last edited:
Upvote
1