Expand list based on value within row

I have a table with two columns, a name and a numerical value. Based on the numerical value, I want to repeat the name that many times. Basically I’m trying to find a method to covert an array into a list based on a value in each row, essentially a ForEach() based on an adjacent value.

Convert this:
{item A, 1; item B, 3; item C, 1; item D, 2; item E, 2} into

Into this:
item A
item B
item B
item B
item C
item D
item D
item E
item E

Any ideas would be greatly appreciated. Thanks!

This gets the job done, but I was curious if there was a more elegant approach. (Fortunately in this case, I’m dealing with a small set of numbers.)

ListCombine(
    Table1.filter(count) >= 1),
    Table1.filter(count) >= 2),
    Table1.filter(count) >= 3)
)

Hi @Nate_Eikelberg

Just a 5 minutes workaround, it can probably be cleaned easily :wink:

This is basically a double foreach function, You’ve got a master button that will activate a slider from 1 to the number of different you have, updating the main table. During this loop, it will also trigger each time an inline button that will add row, according to the number for each item.
Please check the open embed below for detailled formula and how I cut it, and let me know if it requires furthers explanations.

Once more for that kind of issue, I assume that your format is as suggested : “item 1, N1; item 2, N2; …”

CPT2211182140-1198x865

Edit :

Master Button : that update the slider and trigger inline button

Inline Button : that add repeated item in Results table

Hi @Quentin_Morel, thanks for the response. It looks like there was some confusion from my initial query regarding the array notation.

{item A, 1; item B, 3; item C, 1; item D, 2; item E, 2}

Would translate to a table like this:

Name Count
item A 1
item B 3
item C 1
item D 2
item E 2

(my apologies, I didn’t realize the forum supported table markdown until just now.)

Well, this is even easier then :slight_smile:
On this example table, create an inline button like mine, with something like (not in computer anymore) ForEach(Sequence(1,CountColumn),AddRow(ResultsTable,Name,thisRow.Name)
and activate each inline button with a Master Button that will run from 1 to the number of item (here are 5) ForEach(Sequence(1,DataTable.Count()),InlineButton)

Good for you ?

Q.