I have a column consisting of single numbers and blank spaces. The numbers are not unique, but can occur in multiple cells. I want to find the row index for the last number 9 (i.e., in the photo above it is in row 12). What formula can I use for this purpose? I cant get it to work with MATCH or INDEX.
Use LOOKUP which lets you search on a column a specific key (in your case C1, to return the last value 1/(A:A=C1) is used) and returns a specific range of matches (in your case to return the row index the formula takes use of ROW):
=ArrayFormula(LOOKUP(1,1/(A:A=C1),ROW(A:A)))
Try this:
=INDEX(FILTER(ROW(A1:A),A1:A=9),COUNTIF(A1:A,9))
You could try:
=INDEX(MAX(ROW(A:A)*(A:A=9)),)
Related
What I'm trying to do is find the name of the person who is ranked number 1 in the table shown below. I have tried =LOOKUP and =VLOOKUP but I get an error saying that a result can't be found, even though it's obviously there. I assume that I'm either using the wrong function or just not using it right.
I tried =VLOOKUP(1;D2:H19;1) and =LOOKUP(1;D2:H19;1) but neither seems to work.
Answer
The following formula should produce the behaviour you desire:
=INDEX(D2:D,MATCH(1,H2:H,0))
Explanation
=VLOOKUP can only be used to find values to the right of a search key. To find values to the left of a search key, use a combination of =INDEX and =MATCH.
The =MATCH function searches a specified range for a specified value and returns the relative position of the value in that range. In this case, the value to search for is 1, the range to search through is H2:H, and the 0 at the end specifies that the range is not sorted in any way.
The =INDEX function returns the contents of a cell within a range having a specified row and column offset. In this case, the range is D2:D, and the row is whichever row is returned by =MATCH. =INDEX could take a third argument if it was desired to specify a row offset as well, but that is not necessary here.
Functions used:
=INDEX
=MATCH
You sort your ascending order based on rank then return your desired data using INDEX() function. Try-
=INDEX(SORT(D2:H500,5,1),1,1)
=vlookup(1,{H2:H19, D2:D19},2)
Since vlookup only searches the 1st column of the input range, to use it, you need to flip the columns by composing a local array: {H2:H19, D2:D19}.
{} means concatenation. , in it means horizontal concatenation. With that, the rank column is now the 1st column in the input of vlookup and now vlookup works.
With our local array, the 2nd column are the names and therefore index should be 2.
Also note the use of comma to separate function inputs.
your VLOOKUP formula should look like:
=VLOOKUP(1, {H2:H19, D2:D19}, 2, 0)
also try just:
=FILTER(D:D; H:H=1)
or:
=SORTN(D:D; 1; 1; H:H; 1)
You can use query (usefull in case of ex aequo)
=query(D2:H,"select D where H=1",0)
Working in google sheets, I am trying to find the closest matching value ABOVE the current cell and return a different column from that same row.
Here is a visual of what I'm trying to achieve:
For any row where Column A=x, just return the value in Column B to Column "Results". If Column A does not equal x, I want to return the closest (in distance) Column B value where Column A=x above the current row. The first part (where Column A=x) is simple, but I'm having trouble with the second part, where Column A <> x. I've tried various iterations of index match, vlookup, but I keep ending up with either the first or last match, rather than the closest (in distance) above.
Thank you so much!
Try LOOKUP:
=ArrayFormula(LOOKUP(1,1/($A$1:A1="x"),$B$1:B1))
try:
=INDEX(IF(B:B="",, VLOOKUP(ROW(B:B), IF(ISNUMBER(1*B:B), {ROW(B:B), B:B}), 2, 1)))
I filter a dynamic range of Columns as an INDEX in an VLOOKUP, based on a cell reference. In this case I would get three columns back. Afterwards I pick one of them (INDEX 1 in example).
=VLOOKUP($A2, Sheet1!$A$3:$W, index(filter(arrayformula(column(Sheet1!$A$1:$1)),Sheet1!$A$1:$1=E$1),,1),false)
Since I have to return INDEX 2 and INDEX 3 as well and SUM them up afterwards, I pretty much repeat this formula per INDEX (3 times in this example)
=VLOOKUP($A2, Sheet1!$A$3:$W, index(filter(arrayformula(column(Sheet1!$A$1:$1)),Sheet1!$A$1:$1=E$1),,1),false) +
=VLOOKUP($A2, Sheet1!$A$3:$W, index(filter(arrayformula(column(Sheet1!$A$1:$1)),Sheet1!$A$1:$1=E$1),,2),false) +
=VLOOKUP($A2, Sheet1!$A$3:$W, index(filter(arrayformula(column(Sheet1!$A$1:$1)),Sheet1!$A$1:$1=E$1),,3),false)
I am wondering if there is a way to get the SUM of INDEX 1-3 but with just one formula. Here a picture to help understanding my setup:
I am looking for every Column with GroupX as a reference, return Index1 and Index2 and SUM the values afterwards. How can I do that without repeating the formula 3 times and type in the INDEX manually.
Remove INDEX and just use FILTER and it will return multiple columns meeting the condition. Also, you can remove IFERROR here since only valid columns are returned, thus there should be a value always, no #REF values anymore.
Formula E2:
=divide(
sum(arrayformula(switch(VLOOKUP($A2, Sheet1!$A$3:$J, filter(column(Sheet1!$A$1:$1),Sheet1!$A$1:$1=E$1),false),"done",1,"wip",0.5,"open",0)))
,countif(Sheet1!$A$1:$1,E$1))
Formula E7:
=divide(
sum(arrayformula(switch(VLOOKUP($A7, Sheet2!$A$3:$J, filter(column(Sheet2!$A$1:$1),Sheet2!$A$1:$1=E$1),false),"done",1,"wip",0.5,"open",0)))
,countif(Sheet2!$A$1:$1,E$1))
Output:
Note:
IDs ending in B, I used Sheet2, and just copy pasted to rows 7-11
Pardon for the background colors, it wasn't formatted properly like yours.
When using VLookup is there a way to exclude the current row?
I'm trying to determine the following:
If two rows have the same value in column A,
check if they have the same value in column B.
It seems to me that
=exact(B2,vlookup(A2,A:C,2,FALSE))
should be able to do that, the only thing I can't figure out is how to ignore the current row so it doesn't compare itself to itself.
Just starting the vlookup range one row lower than the current row would work, except it's possible that the row with the matching value in column A is either above or below the current row.
Thanks!
If two rows have the same value in column A,
check if they have the same value in column B.
use:
=ARRAYFORMULA(IF(A2:A&B2:B="",,COUNTIFS(
FLATTEN(QUERY(TRANSPOSE(IFERROR(CODE(REGEXEXTRACT(A2:A&B2:B,
REPT("(.)", LEN(A2:A&B2:B)))))),,9^9)),
FLATTEN(QUERY(TRANSPOSE(IFERROR(CODE(REGEXEXTRACT(A2:A&B2:B,
REPT("(.)", LEN(A2:A&B2:B)))))),,9^9)))>1))
Use COUNTIFS instead:
=COUNTIFS(A:A,A2,B:B,B2)>1
You can use the range you want to check for the vlookup
So you can use this query: =exact(A1,vlookup(A1,A1:B4,2,FALSE))
Note: A1:B4 is the range for the vlookup.
For more about vlookup you can check: Link.
I have several columns in Google Spreadsheet.
I would like to count how many cells have a value (number or string) and display that number at the top of the column.
For example:
Hello
World
123
Some string
The above column would give me the answer of "4"
I have not managed to find a formula that does this.
In the cell you want your result to appear, use the following formula:
=COUNTIF(A1:A200,"<>")
That will count all cells which have a value and ignore all empty cells in the range of A1 to A200.
You could also use =COUNTA(A1:A200) which requires no conditions.
From Google Support:
COUNTA counts all values in a dataset, including those which appear
more than once and text values (including zero-length strings and
whitespace). To count unique values, use COUNTUNIQUE.
An additional trick beside using =COUNTIF(...) and =COUNTA(...) is:
=COUNTBLANK(A2:C100)
That will count all the empty cells.
This is useful for:
empty cells that doesn't contain data
formula that return blank or null
survey with missing answer fields which can be used for diff criterias
Shorter and dealing with a column (entire, not just a section of a column):
=COUNTA(A:A)
COUNTA
Beware, a cell containing just a space would be included in the count.
The SUBTOTAL function can be used if you want to get the count respecting any filters you use on the page.
=SUBTOTAL(103, A1:A200)
will help you get count of non-empty rows, respecting filters.
103 - is similar to COUNTA, but ignores empty rows and also respects filters.
Reference : SUBTOTAL function