user25539466
user25539466

Reputation: 41

Creating a sequence table with different column counts

I'm hoping to create a TOCOL in excel of an array of values based on variable criteria. Eg. When it meets one criteria, I wish for it to be able to return an array of values associated with that criteria (eg stores in that region), and when it meets another criteria return values associated to that criteria.

Sales Region Number of stores Criteria
www WA 3 FALSE
xxx WA 3 TRUE
yyy NSW 2 TRUE
zzz VIC 4 TRUE

There would be another table to lookup data which I wish to return (eg replenishment stock)

Tried playing around with SEQUENCE and TOCOL and I am reliably able to get a static value =IFERROR(TOCOL(CHOOSE(SEQUENCE(1,COUNTIF(\_sloc_repl\[Repl type\],XLOOKUP(TEXTAFTER(CELL("filename",$A$1),"\]"),\_tool\[Material type\],\_tool\[Repl type\])),1,0),FILTER(\_tool\[Criteria\],\_tool\[Criteria\]=TEXTAFTER(CELL("filename",$A$1),"\]"))),,0),"")

In this case I can get a result of

xxx
xxx
xxx
yyy
yyy
yyy
zzz
zzz
zzz

(which is a sequence based on the count of the first criteria found [3])

What I am hoping to achieve is

xxx
xxx
xxx
yyy
yyy
zzz
zzz
zzz
zzz

Which is a limited repeat of the value associated to the matching criteria

Upvotes: 4

Views: 145

Answers (3)

Black cat
Black cat

Reputation: 6271

Apply this formula for the table range

=DROP(TOCOL(TEXTSPLIT(TEXTJOIN("",TRUE,IF(D2:D5,REPT(A2:A5&"|",C2:C5),"")),"|")),-1)

or as @Harun24hr proposed:

=TOCOL(TEXTSPLIT(TEXTJOIN("",TRUE,IF(D2:D5,REPT(A2:A5&"|",C2:C5),"")),"|",,TRUE))

enter image description here

Upvotes: 1

z..
z..

Reputation: 13013

Another solution:

=TOCOL(IF(D2:D5,IF(SEQUENCE(1,MAX(C2:C5))>C2:C5,0/0,A2:A5),0/0),2)

enter image description here

Upvotes: 2

Harun24hr
Harun24hr

Reputation: 37050

You may give a try to the following formula-

=TOCOL(TEXTSPLIT(TEXTJOIN("",1,REPT(FILTER(A2:A5,D2:D5=TRUE)&"|",FILTER(C2:C5,D2:D5=TRUE))),"|",,1),1)

enter image description here

Upvotes: 3

Related Questions