Results 1 to 5 of 5

Thread: Finding the position of the Nth match in an array with multiple criteria

  1. #1
    New Member
    Join Date
    Aug 2019
    Location
    UK
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Finding the position of the Nth match in an array with multiple criteria

    Hello all I hope someone can help me please, I've tried searching lots of sites for an answer but so far I haven't been successful...

    In my worksheet, each row contains one of certain text values in columns CL to CV - either 'Transferred', 'Abandoned', 'Consult', 'Call Ended' or 'NULL', as illustrated below:

    CL CM CN CO CP CQ CR CS CT CU CV
    2 Transferred Consult Consult Abandoned Transferred Consult Call Ended NULL NULL NULL NULL

    Assuming column CL always contains 'Transferred', I want to find out the position (in this array) of the next column to contain EITHER 'Transferred' or 'Call Ended'. I.e. in the example above I would expect to return a 5 because column CP contains 'Transferred' and is the fifth column in the array CL:CV.

    I can already find the position of the 'Nth' match based on a single criteria - for example if I just wanted to know the position of the next column after CL to contain 'Transferred' I would use this array formula:

    {=SMALL(IF(CL2:CV2="Transferred",COLUMN(CL2:CV2)-COLUMN(CL2)+1),2)}

    So, I tried introducing an 'OR' argument as shown below, but this doesn't work because it always returns a 2:

    {=SMALL(IF(OR(CL2:CV2="Transferred",CL2:CV2="Call Ended"),COLUMN(CL2:CV2)-COLUMN(CL2)+1),2)}

    With a bit of googling I think I've learned that 'OR' just doesn't work with SMALL IF, but this is where I'm stumped.

    Can anyone help me solve this please?

    Thanks

  2. #2
    Board Regular
    Join Date
    Dec 2008
    Posts
    6,643
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Finding the position of the Nth match in an array with multiple criteria

    When you use OR it only gives a single result, not an array.

    See if this one does what you need. Note that if you are in a country where you have to use ; instead of , then you might need to change the ; that is already in the formula to \

    =AGGREGATE(15,6,COLUMN(CL2:CV2)/(CL2:CV2={"Transferred";"Call Ended"}),2)-COLUMN(CL2)+1

  3. #3
    New Member
    Join Date
    Aug 2019
    Location
    UK
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Finding the position of the Nth match in an array with multiple criteria

    Quote Originally Posted by jasonb75 View Post
    When you use OR it only gives a single result, not an array.

    See if this one does what you need. Note that if you are in a country where you have to use ; instead of , then you might need to change the ; that is already in the formula to \

    =AGGREGATE(15,6,COLUMN(CL2:CV2)/(CL2:CV2={"Transferred";"Call Ended"}),2)-COLUMN(CL2)+1
    Hi Jason, unfortunately that doesn't seem to work once it's copied down all rows - for example on a row containing 'Call Ended' in column CM (i.e. the 2nd column), it returns a 3.

    However, it gave me an idea...

    I swapped the 'OR' argument out of my original attempt and instead used semicolon-separated values in curly brackets (like you used in your AGGREGATE formula) for the conditional test of the IF statement, like so:

    {=SMALL(IF(CL2:CV2={"Transferred";"Call Ended"},COLUMN(CL2:CV2)-COLUMN(CL2)+1),2)}

    and it does exactly what I wanted because it returns an array of results instead of a single result.

    So thanks very much for your reply because, without seeing it in your solution, I probably wouldn't have thought to try that!

  4. #4
    Board Regular
    Join Date
    Dec 2008
    Posts
    6,643
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Finding the position of the Nth match in an array with multiple criteria

    I don't see why one would work and not the other, aggregate(15,6 is exactly the same as {small(if(

    I just tried 'Call Ended' in CM and it returned 2 as expected, the only exception should be is if CL didn't contain Transferred.

    Not critical though, as long as you have something that does what you need it to, that's the important thing.

  5. #5
    New Member
    Join Date
    Aug 2019
    Location
    UK
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Finding the position of the Nth match in an array with multiple criteria

    Quote Originally Posted by jasonb75 View Post
    I don't see why one would work and not the other, aggregate(15,6 is exactly the same as {small(if(

    I just tried 'Call Ended' in CM and it returned 2 as expected, the only exception should be is if CL didn't contain Transferred.

    Not critical though, as long as you have something that does what you need it to, that's the important thing.
    Apologies, I just tried your formula again and compared the results, and you're quite right! I think I know what I did - I must have offset the formula by one row by mistake, i.e. pasted it in row 3. I blame a lack of caffeine...

    Looks like both formulas are equally valid, and I can wrap them in an IF statement to handle any instances in my data where CM doesn't contain 'Transferred' (which I'm not interested in anyway).

    Thanks again for your help

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •