Forum

Notifications
Clear all

CHOOSE function with a variable number of choices?

6 Posts
3 Users
0 Reactions
58 Views
(@dgantony)
Posts: 3
Active Member
Topic starter
 

Hi All,

    Ever since the new Dynamic Arrays were released, I've been trying to make my calculations use the spill functionality as much as I can. I've been stuck on this one for a while now and thought I'd reach out to see if anyone has a solution. 

    I'm trying to fit a trend line using the SLOPE and INTERCEPT functions. They both accept two arguments like this : SLOPE(C2:C52,B2:B52) / INTERCEPT(C2:C52,B2:B52) where column C contains the Y values and column D contains the X values. Works great. 

    I have multiple X value ranges (in columns D, E, F, ...). The number of columns can vary so I want to make it dynamic. SLOPE(C2:F52,B2:B52) will fail since SLOPE is expecting a one dimensional range. I got around this by using the CHOOSE function like this: 

CHOOSE({1,2,3},SLOPE(C2:C52,B2:B52),SLOPE(D2:D52,B2:B52),SLOPE(F2:F52,B2:B52))

This does 3 columns perfectly. How do I make it so that I can send a variable number of items (could be a lot of columns, so typing them in is not a great option) into the CHOOSE function. The first part is easy with the SEQUENCE function. I'm stuck on the second part. Any help would be appreciated. 

Thanks,

George.

 
Posted : 26/12/2020 9:31 am
(@purfleet)
Posts: 412
Reputable Member
 

can you upload an example worksheet so we dont have to try and recreate the data

 
Posted : 26/12/2020 4:06 pm
(@dgantony)
Posts: 3
Active Member
Topic starter
 

Here's a sample workbook. Thanks for helping.

 
Posted : 26/12/2020 4:43 pm
(@purfleet)
Posts: 412
Reputable Member
 

Probably not what you are after, but.....

I used the offset function to get the next column, but it does need a number to offset by. I couldnt get th sequence function to work within the offset (guessing it doesnt support arrays, but not had a chance to check). So i took the number from the header row

You still have to drag the formula over but it seems to work

 
Posted : 28/12/2020 8:58 am
(@fluff)
Posts: 36
Eminent Member
 

Once again probably not quite what you want, but two options.

1) if you have the LET function

=LET(Rng,B2:G47,CHOOSE(SEQUENCE(,COUNT(B2:G2)),SLOPE(INDEX(Rng,,1),A2:A47),SLOPE(INDEX(Rng,,2),A2:A47),SLOPE(INDEX(Rng,,3),A2:A47),SLOPE(INDEX(Rng,,4),A2:A47),SLOPE(INDEX(Rng,,5),A2:A47),SLOPE(INDEX(Rng,,6),A2:A47)))

2) A formula that doesn't spill

=SLOPE(FILTER($B$2:$G$47,$B$1:$G$1=J6),$A$2:$A$47)

 
Posted : 28/12/2020 10:36 am
(@dgantony)
Posts: 3
Active Member
Topic starter
 

Thank you Purfleet and Fluff. I'll try your solutions.

 
Posted : 28/12/2020 1:22 pm
Share: