Get Row Value based on count - google-sheets

I have a google spreadsheet document and I am trying to list next person's turn. Essentially a user will enter a number and by the count of total numbers entered, the next person is shown.
Normally if I wanted to list a value from another cell I would type
=B2
However I need my number 2 to be dynamic, so something like:
=BCOUNTA(A2:A900)
Of course the above doesn't work, how do I get it to work?
EDIT: Found an answer with INDIRECT

INDEX have optional rows&columns offset.

Related

Google Sheets: Find last non empty cell in a row and extract cell value from different row

I have an attendance list chart, that looks like this:
The list is forever expanding to the right. I would like to be able to calculate days since last attendance, by subtracting the date of last occurrence of any string from today's date. Dates are stored in the first row, every row below is a certain person, emojis symbolize attendance.
I tried fiddling with =DATE360( ..., TODAY()) and various FILTER(), INDEX(), LOOKUP() functions but to no avail. WHat is the easiest way to achieve it?
I found a way. Better ones exist, I am sure, and hope someone would provide them, but I came up with this:
=DAYS360(INDEX(P$4:$4;1;MAX(MATCH("✋";P7:7);MATCH("👑";P7:7)));TODAY())
It finds the relative column number of the last instance of characters specified within MAX() and then extracts the date using INDEX() function.

Get index of second match in Google Sheets

In a sheet made of names and scores, I am trying to build a sheet to display the name of the people with the best scores.
To do so:
I sort the scores
I get the index of the biggest value
I offset the names list with the given index
When I want to get the second biggest value, I only have to get the index of the second biggest value on step 2.
There is a problem if two values are tied for the biggest, as MATCH() will always give me the index of the first value found.
I thought of determining the index of the biggest value, then excluding this index from the range used to determine the second biggest value, but I could not achieve it as the range lengths may be different.
I also thought of using a function or script that returns the Nth index that meets a criteria from a range, but I did not find anything to do so.
Image
Here is an example spreadsheet
https://docs.google.com/spreadsheets/d/1RrUpAjbMBze9L5OqxdyEWBnYXq98LtohdgROF8s68FI/edit?usp=sharing
One way is to add a column number and sort on that as well as on the score, then take the second element in the list:
=ArrayFormula(index(sort(transpose({B1:F3;column(B1:F3)}),3,false,4,true),2,1))
Note that the headers (players' names) are sorted along with their scores.
EDIT
Actually Sort in GS is a stable sort (in other words, according to the documentation 'range is sorted only by the specified columns, other columns are returned in the order they originally appear') so this is sufficient:
=ArrayFormula(index(sort(transpose(B1:F3),3,false),2,1))

Total Value based on Group cross reference? (Google Sheets)

I'd like to query a couple of tables to come up with a total sum of the value of a set of items, but with the price being dependent on data in another cell range, then grouping it based on category.
For example, say I have a data table containing name, category, and price of some grocery items. Another table I store my current inventory of groceries. I would like to calculate the value of, say, all my fruit.
Here is an editable example:
https://docs.google.com/spreadsheets/d/1y2fLgwrsMr-dWojy3uYZ1Qs2U01AP3RlT_PI2txwZRE/edit?usp=sharing
Not sure the best way to approach this?
Thanks for any guidance!
Solution
Use VLOOKUP for searching the right item of your inventory and then multiply it with the value of the product you made the search with. For more info about VLOOKUP check this documentation.
=VLOOKUP(E3,$A$3:$C$11,3,FALSE)*F3
With these values, create a column next to Quantity indicating the total price for each product (as show in the picture below). Then, create another column with the Type of each item performing a similar VLOOKUP formula:
=VLOOKUP(E3,$A$3:$C$11,2,FALSE)
Finally, use these two columns as input ranges to apply a SUMIF formula for adding up the items of each group:
=SUMIF(H3:H6,"Fruit",G3:G6)
For more info about SUMIF check this documentation.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Google Sheets - get the right-most value of a row

I have a sheet where the columns are months in a year and the rows are various metrics. Every month, we add another column on the right.
I need something that I can give a ROW and it will always return the right most value. That is, it automatically updates whenever we add a column for a new month.
There's a few ways of doing it, but one way (considering row 2 in this example):
=FILTER(2:2,COLUMN(2:2)=MAX(FILTER(COLUMN(2:2),LEN(2:2))))
I was very happy to have found #AdamL's answer and it did make my day, but I have since found a simpler way that works fine for my data sample, and that is using the LOOKUP function.
The LOOKUP function will look for a certain value in a given range, but if you pass it a humongous value, a value that is over your data range, it returns the last, rightmost value by default.
The answer is then very simple, just pass it the range - or row if that's what you need - and a huge value (many people do this using the biggest number that Excel can handle, but Google sheets is not Excel, and since I don't know what is the biggest number Google sheets can handle, I'll just give it a value well outside of my data set). Assuming you need to lookup into the entire row number 2:
=LOOKUP(999999999,2:2)
And that's it.
This function will throw an error if there isn't any data, so if you (like me) need to get that particular value only if it exists, you can combine this with a simple IF function:
=IF(ISERROR(LOOKUP(999999999,2:2)),"EMPTY",LOOKUP(999999999,2:2))
You can replace the string "EMPTY" with any value or function you want in there if the LOOKUP function returns an error.
I hope this simpler method is of any help, and thanks again to #AdamL for his original answer.
Adding this one for future readers. The formula I found years ago for obtaining the rightmost value was:
=index(2:2,1,COUNT(2:2))
However for each blank cells in amongst the cells with data, the returned value is the Nth last value (2 blank cells in row 2 and the formula will return the 3rd last value from the right, not the rightmost value). It appears to work, but won't be accurate in all cases.
As such, I do not recommend this formula as you can not depend on it if ever there will be an empty cell before the right-most within your data.

=MATCH() returns wrong value

Why doesn't this work? I have the share of votes of different Finnish parties in the City of Jyväskylä in every region.
Every row shows one region, every column has the share of votes of every party. I'd like to add a column where Google Spreadsheet would find out which column has the maximum value on that particular row and then return the text on the header row of that column.
In other words I'd want to add "The biggest party column" that would show which party got the biggest share of votes in every region.
I think that should be possible using =max()-function to find out the maximum value, then using =match() function to give the column index number of the cell that has the biggest value on row and finally use =index()-function to return the party's name from header row.
Any ideas what I'm doing wrong?
MATCH needs a third argument of zero for your case (to get an exact match). Change formula to
=INDEX(C$1:M$1,MATCH(MAX(C2:M2),C2:M2,0))

Resources