Google Spreadsheet Formula to get last value in a row - google-sheets

I wondered if someone could help me with what I hope is a simple Formula.
I have a simple spreadsheet for Product which has a column for the product name eg
Product A
Product B
Product C
Product D
Now on each row there are some numerical values
eg
Product
Product A 5.0 2.5
Product B 6.0
Product C 2.0 4.0 5.0
Product D 3.0
Product E 6.0 2.0 1.6 2.9
Now what I want is to have a formula for a Column next to the prouct that shows me the value of the last entered value for a Product eg
the Values in the above example would give me
Product A 2.5
Product B 6.0
Product C 5.0
Product D 3.0
Product E 2.9
In Excel I would do this with INDEX and MATCH however I cannot get this to work in Google Spreadsheets.
Any ideas would be most welcome.
Here is a screenshot of what I would like it to look like.
http://i.imgur.com/jqcNW.png
Many thanks in advance

For me this one works better, mainly because it works with any other formulas in the same row:
=LOOKUP(9999999999; (B2:G2))

I managed to do it :)
Formula
=index(B2:G2;1;counta(B2:G2))

Will update #mik's answer once I have a high enough reputation.
As a more general answer than #mik's, you can have a formula that slides with the placement of the data:
=index(B2:G2, 0, max(ARRAYFORMULA(column(B2:G2)*(B2:G2<>""))) - column(B2) + 1)

I used a similar solution to #DannyhelMont, but I adapted it to work with strings. I had to fill the first column in the range with values to keep from getting an error.
The string of z's is intended to appear alphabetically later than every other possible string. The hlookup function returns the last value which is less than or equal to the search value. (If you're doing numbers, use 9999999999 instead of the z's.)
=HLOOKUP("zzzzzzzzzz",B2:G2,1,true)
This has an advantage over the index/counta solution given by #DarkUFO because it doesn't depend on the number of cells with values. If any cell in the range is empty, counta returns a number less than the offset of the last cell. The hlookup solution can have empty cells. If all cells are empty it gives an error.

If you can have both numbers and strings, or do not know a value that is greater than any possible number or string, you can do:
=index(B2:G2,1,max(arrayformula(column(B2:G2)*(B2:G2<>"")-1)))

This will return the value of the 1st column and last row of a range named RangeName:
=INDEX(RangeName, ROWS(RangeName), 1)
where RangeName is the name or range you are looking at. ROWS returns the number of rows in that range.

Related

How do I display the value of a cell in one column based on the value of a cell in a different column?

I have a simple table.
Column A are dates (rows 2 to 100) that reflect approximately the next 3 months.
Column C are percentages that range from 0 to 1 (i.e. 0% to 100%). The %s are derived from a =FORECAST function.
I want to query a date in column A based on a value of 100% in column C. However, the QUERY function does not work because it's reading the =FORECAST formula in column C rather than the text or value of "100%" itself. (In other words, if I remove the =FORECAST formula and type in the string "100%", the query works.
How can I pull the date value in Column A and keep the formulas used in column C?
This sounds like a lookup to find the value in column A on the first row where column C contains the value 100%. Try this:
=vlookup(100%, { C2:C, A2:A }, 2, false)
In the event multiple rows in column C may contain 100%, and you want to get all such dates, try this:
=filter(A2:A, C2:C = 100%)
In the event your forecast() numbers do not produce exact percentages but figures like 100.04%, use this:
=filter(Forecast!A2:A, round(Forecast!C2:C, 2) = 100%)
Thanks to everyone who contributed. My workaround was replacing the = sign with a > sign, as shown:
=QUERY(StageHist!A:H, "SELECT A WHERE C>.99")
since I couldn't figure out how to make the 100% figure an exact 100%. Apparently the =FORECAST formula is designed to give a result with 8 or 9 digits to the right of the decimal. (Although I'm sure that I could nest a =ROUNDing function inside of FORECAST and get an exact 1.0 value. (A project for another day!)

Check columns, if one is bigger or equal to the adjacent cell in column A, style it differently

I have 10 columns with price data in.
Column A has my product SKU
Column B - has the cost price of a product
The other columns have other prices in them.
Link: https://docs.google.com/spreadsheets/d/17PLI_d_05uYnzOt2yL4ZQA3XB89rIz9vQJnIOBidMz8/edit?usp=sharing
I want to go through each cell in a row and see if any of the prices listed are less than, or equal to, the cost price in Cell A.
How would I write this in Google Sheets?
I believe the correct way to do this is the following formula:
=$D2:$K2<=$B2
To check if there is any price below (or equal) to a certain value, you could check the minimum price and compare that. So use the MIN function and compare that with the value at B2.
=MIN(D2:K2)<= B2
You have posted a solution but you are comparing a range with a value, and for me it does not work.

Getting a column header from the min value, excluding zero

I'm trying to make a spreadsheet to find the best price of a product in Google Sheets. I have the product description on B column, starting from the sixth row and below, the prices are on column E6 and on, (F6, G6, H6,...) Each supplier name is written on the fist row of their Columns. The lowest price is in column C and Column D displays the supplier with that price.
I've tried the min() function, but there's an issue, I need it to bypass 0 values.
On column C, I'm using this code =min($E6:$Z6) and for displaying the supplier I'm using =index($E$1:$Z$1,0,match(min($E6:$Z6),$E6:$Z6,0))
I'll add a screenshot of the problem.
wrap it into simple IF or IFERROR
=IF(MIN($E6:$Z6)=0, , MIN($E6:$Z6))
and the second one:
=IFERROR(INDEX($E$1:$Z$1, 0, MATCH(MIN($E6:$Z6), $E6:$Z6, 0)))

Unable to Parse Formula Using MINUS Function in Google Sheets

I have two columns in a Google spreadsheet. One column ("amountPaidByBuyer" or column "G") contains the amount buyer paid for product. The second column ("cost" or column "J") contains the amount our company paid for the product. I have a 3rd column ("ROI") which should contain the difference between the cost and the amount paid by buyer (for example, if cost is 10.99 and the buyer paid 11.99 then the ROI is +1.00. If the cost is 10.99 and the buyer paid 9.99 then the ROI is -1.00).
Since I'm simply subtracting two columns from the same row (G - J) I tried inserting the following formula:
=MINUS(G ROW(),J ROW())
This was done based on the following answer which suggests using the ROW() function to get the current row automatically (instead of needing to specify this value in the formula).
However, this leads to the following error: Formula parse error.
Google does not provide any additional details about the error.
What is wrong with the formula?
If you want to use minus and row(), this will work:
=minus(indirect("G"&ROW()),INDIRECT("J"&ROW()))
But why not use:
=G2-J2
Change the row to where you start then drag the formula down for rows below.
What’s wrong with the formula is too much for Sheets’ help features to cope with:
i. MINUS requires numeric parameters and G ROW() is not numeric.
ii. G ROW() is merely a string of characters, including a space. In Excel, for example, a space may be an intersect operator – but space does not function as such here. (Even with the update a few minutes ago Sheets does not have an intersect operator.)
iii. To combine a column reference with a row reference to make a cell reference concatenation is required (eg use of & operator).
iv. But G&ROW() does not work because Sheets does not recognise G as a column name, without quotes round the G (unless a column has been given the range name of G).
v. "G"&ROW() returns a cell reference, but not the value in that cell, so not the numeric parameter required by MINUS.
vi. To interpret the cell reference as the value within the cell a function like INDIRECT is required.

Getting Corresponding Cell In Google Sheets?

I have a Google sheet for tracking my weight. I have two columns: Date and Weight. While the goal is to have the weight column sorted in descending order, that doesn't always happen in reality...
The data essentially looks like this (weights changed to far lower values, of course):
Date |Weight
04/01/10|195
04/02/10|194
04/03/10|190
04/04/10|198
etc.
Anyway, I have a cell in another spot on the sheet that shows the minimum value from the weight column using this formula
=(Min(B:B))
What I would like to do is display the corresponding date cell for whatever the minimum value from the weight column is. So, with this dataset, I want to show 190 for weight and 04/03/10 for date. Is there any way to get that corresponding cell? I looked through the function reference for Google docs, but can't get anything going. I tried using some of the functions from the Lookup category, but got nowhere. Most want a cell reference, but the min() function returns a value. I think I need to somehow get min() to give me a cell reference, but I don't know how to do that. HLOOKUP() sort of seemed like it might be appropriate, but the docs were a bit spotty, and it didn't do anything but error out the cell.
Of course, I may be barking up the wrong tree entirely.
Thoughts?
I would use the following two formula's:
MIN(B2:B)
FILTER(A2:A;B2:B=minimal value)
If there are more results, they need to be included as well.
See example file I've created: Getting Corresponding Cell In Google Docs Spreadsheet?
Not barking up the wrong tree, actually very close:
=index(A:A,match(min(B:B),B:B,0))
should meet your requirement.
Working inside out: min(B:B) (as you had) returns the lowest weight (ie 190) in ColumnB.
match then finds the position of that value relative to the start of the range in which the value is searched for. So assuming Date is in A1, that returns 4, being the fourth row in ColumnB, where 190 is. The 0 in the formula is to ensure that only the position of an exact match is returned.
Now we know we need the content of the fourth row we can go looking for the value there in ColumnA with index, returning 04/03/2010.
Not all is ideal however. It is possible that a weight of 190 was achieved on separate days. It is the nature of match that where an exact match is required and found the function stops looking for any further instances. Hence as things stand 04/03/2010 will be returned for 190 however often that is the weight for a day after 04/04/2010 - unless other steps are taken, such as to delete/remove/ignore data from 04/03/2010.
You need to change the order of the column as the search column (the weight should be the first in the search array. Then you can use the VLOOKUP formula:
=VLOOKUP(C7,A:B,2,false)
C7 holds the MIN formula that you used: =(Min(A:A)) - note the column order change
one-cell solution to get minimal value with the latest day:
={MIN(B:B), TO_DATE(VLOOKUP(MIN(B:B), SORT({B:B,A:A}, 2, 0), 2, 0))}
to get all minimal values with dates:
=QUERY(A:B, "select B,A where B matches '"&MIN(B:B)&"' order by A desc", 0)

Resources