Apr 22, 2019

I am trying to reference the first second occurrence of a name to index numerical values.

I am attempting to index a column that contains unique numerical values (B2:B100) some of which are blank, by comparing one name (I4 - single cell reference) to a list of names (C2:C100). There are duplicates names in column (C2:C100) that have unique values in B2:B100. I have tried with no avail to reference the 1st, 2nd occurrence with the INDEX, SMALL and MATCH functions. The formula just returns the first then second cell in column B (B2 then B3)... but not the correct B column value corresponding to the indexed name in column C...
 
Here is the current formula:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$B$2:$B$100,SMALL(IF(COUNTIF(Alaska!$C$2:$C$100,I4),MATCH(ROW(Alaska!$C$2:$C$100),ROW(Alaska!$C$2:$C$100)),""),ROWS($A$1:A1)),0),"X")), 1, 1)

Of note - column C2:C100 is generated from a drop down menu in a separate tab. In the above formula I4 is the single cell reference. This value is generated by an index-match array from the same C2:C100 list to filter the names that I need to get information for. What I tried to do is INDEX (unique numbers), SMALL(IF(COUNTIF(one name occurs once or more than once in a table of names...which it has to because the names are generated from the same column of data),MATCH(location of duplicates), ROWS(generate nth occurence), enter "X" if there is an error.

Thank you for the assistance.
Locked
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
Recommended Answer
Apr 23, 2019
Hello Alaska,

It was great working with you on your sheet. We went a little bit of a combination of what you already had and some other stuff to get this one for you. Here is the formula we came up with and you can modify slightly for each different sheet.

=QUERY(ArrayFormula(IF(COUNTIF({ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A1)),COLUMNS($A$1:A1)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A2)),COLUMNS($A$1:A2)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A3)),COLUMNS($A$1:A3)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A4)),COLUMNS($A$1:A4)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A5)),COLUMNS($A$1:A5)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A6)),COLUMNS($A$1:A6)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A7)),COLUMNS($A$1:A7)),"")), 1, 1)},Alaska!C2:C)>0,Alaska!B2:C,"")),"select * where Col2 is not null",0)

It looks big but most of that is building the literal array to get the list to countif against.

Stephen
Last edited Apr 23, 2019
Original Poster Alaska 7DR marked this as an answer
Helpful?
All Replies (7)
Apr 22, 2019
Hello,

While it is easy for you to see and understand what you're needing done it can be difficult for us to try and visualize what you need. For us to best help you please share a copy of your sheet with private data changed. Tips for sharing a sheet here https://support.google.com/docs/thread/3808684?msgid=3808684

Stephen
Last edited Apr 23, 2019
Apr 23, 2019
Hi, does this formula give the right result:

=IFERROR(IF(LEN(I4),FILTER(ROW(C:C),C:C=I4),1/0),"X")

If not, please Share an example sheet as Stephen has suggested
Apr 23, 2019
This feels to me like you might be shoehorning the old excel way of doing things when a FILTER() might do.
 
I'll second Stephen's suggestion of sharing a sample sheet, but also wanted to direct you to the Google documentation on FILTER() to see if that might help get at what you're after.
 
Cheers,

Matt
Apr 23, 2019
Thank you all for the help. The formula works great to reference the row. I can then index based on that row number, but am still having problems if the 'name' category gets filtered... this is a pretty dynamic sheet as you will see, and the names get filtered frequently.

Here is a copy of the sheet. I started a tab "Formula Tests" to test out the formula and hid the remainder of the sheet and tabs that aren't being used for ease of viewing.

I think your formula would work if I added a few helper columns to sheet 'Alaska', but there might be an easier or better solution now that you can view the sheet. The helper columns would

1 - sort all names in column C from A-Z.
2 - your formula to reference ROW in column B

Then I would need a new function to index and match based on the new data, but this will need to be entered on 'Team Generator' tab where the names are drawn given an array function that changes based on ROW 2... and gets sorted from sheet to sheet based on preference of other users.
 
Thanks again for the help
Recommended Answer
Apr 23, 2019
Hello Alaska,

It was great working with you on your sheet. We went a little bit of a combination of what you already had and some other stuff to get this one for you. Here is the formula we came up with and you can modify slightly for each different sheet.

=QUERY(ArrayFormula(IF(COUNTIF({ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A1)),COLUMNS($A$1:A1)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A2)),COLUMNS($A$1:A2)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A3)),COLUMNS($A$1:A3)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A4)),COLUMNS($A$1:A4)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A5)),COLUMNS($A$1:A5)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A6)),COLUMNS($A$1:A6)),"")), 1, 1);ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(INDEX(Alaska!$C$2:$C$104,SMALL(IF(COUNTIFS($A$2,Alaska!$I$2:$I$104,$A$3,Alaska!$A$2:$A$104),MATCH(ROW(Alaska!$C$2:$C$104),ROW(Alaska!$C$2:$C$104)),""),ROWS($A$1:A7)),COLUMNS($A$1:A7)),"")), 1, 1)},Alaska!C2:C)>0,Alaska!B2:C,"")),"select * where Col2 is not null",0)

It looks big but most of that is building the literal array to get the list to countif against.

Stephen
Last edited Apr 23, 2019
Original Poster Alaska 7DR marked this as an answer
Apr 23, 2019
Stephen - thank you for not only answering my question but for taking the time to explain how your query worked inside of the sheet. 

Amazing work friend that is much appreciated!
Apr 23, 2019
Glad to help!

I prefer to explain how it works so you are able to trouble shoot and/or make adjustments in the future if needed.

If you have more questions come back to the forum there are many people on here who are great help!

Stephen
false
1161209825949056096
true
Search Help Center
true
true
true
true
true
35
false
Search
Clear search
Close search
Main menu