How do I get Excel to return a value based on the max value in a table? - excel-2010

In the table the largest value is 1.71, how do i return -2.25 and 235?

It appears from your picture that you need a two-dimensional lookup. Given a value within a table, retrieve both the column header and row header associated with that value. Consider the following simple example:
We want the name and topic associated with the highest score. The highest score in the example is 100; so we want to retrieve Jim and Spelling
In A7 enter:
=MAX(B2:F5)
This is our lookup value. In B8 we enter the array formula:
=INDEX($B$1:$F$1,1,MIN(IF($B$2:$F$5=A7,COLUMN($B$2:$F$5)-COLUMN($B$2)+1)))
In B9 enter the array formula:
=INDEX($A2:$A$5,MIN(IF($B$2:$F$5=A7,ROW($B$2:$F$5)-ROW($B$2)+1)),1)
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
The result:

Related

How do I get the column letter of a single row where a particular value equals a test value?

I need to get the letter of the column that has a value in a given row that matches a given value in Google Sheets, assuming that no values in the row are duplicates.
For example, in the above screenshot, if the row is the first row, and the test value is Jun, the formula will return H.
Kind of meta. Appreciate any help.
Answer
The following formula should produce the behaviour you desire:
=REGEXREPLACE(ADDRESS(1,MATCH("Jun",A1:1),4),"[1-9]*",)
Explanation
The =MATCH formula returns the position of the item in a range which has a specified value. In this case, the specified value is "Jun" and the range is A1:1.
=ADDRESS returns the A1 notation of a row and column specified by its number. In this case, the row is 1 and the column is whichever number is returned by the =MATCH. The 4 is there so that =ADDRESS returns H1 instead of $H$1 (absolute reference is its default).
=REGEXREPLACE looks through a string for a specified pattern and replaces that portion of the string with another string. In this case, the pattern to search for is any number. The last argument of =REGEXREPLACE is blank so it simply removes all numbers from the string.
What is left is the letter of the column where the value is found.
Functions Used:
=MATCH
=ADDRESS
=REGEXREPLACE
Now that Google Sheets has added Named Functions, there is an easier way to do this.
To use named functions, go to Data -> Σ Named Functions. A sidebar will pop up. At the bottom use "Add new function" to create a new named function.
I created two functions to do this:
First, COL_CHAR which will take a column reference and return its letter
Second, ALPHA_CHAR which takes a numeric input and converts it to letters. I made this one recursive, so if it's an n-letter column name, it will keep calling itself until it gets the full name.
COL_CHAR just converts the referenced column to a column number and passes that to ALPHA_CHAR. It's formula is:
=ALPHA_CHAR( column(cell) )
where cell is an Argument placeholder. Make sure to add that to the argument placeholder list in the sidebar.
Here is the (recursive) formula for ALPHA_CHAR:
=IF( num > 26, ALPHA_CHAR( INT( num / 26 ) ), "") & CHAR( CODE("A") - 1 + MOD( num, 26 ) )
where num is an Argument placeholder.
By making this recursive, even if Google Sheets expands to allow 4-letter (or more) columns in the future, it will keep iterating through every letter regardless of how many there is.
Then, to get the letter of a column in the spreadsheet, you just call COL_CHAR and pass the cell in the column you want, for example:
= COL_CHAR(BK1)
Will return the string "BK"

How can I get the last numerical value value in a column in Google Sheets?

I need to find the last numerical value in a column. I was using this formula to get the last value in column G, but I made some changes and it no longer works: =INDEX(G:G, COUNTA(G:G), 1). My column now looks like this:
645
2345
4674.2345
123.1
"-"
"-"
"-"
...and the formula returns "-". I want it to return 123.1. How can I do this?
There are many ways to go about this. Here is one of them:
=QUERY(FILTER({G:G,ROW(G:G)},ISNUMBER(G:G)),"Select Col1 ORDER BY Col2 Desc LIMIT 1")
FILTER creates a virtual array of only numeric values in G in the first column and the row of those numeric values in the second column.
QUERY returns flips the order by row number and returns only the new top value from the first column (which winds up being your last numeric value in the original range).
However, if your numeric values start at G1, and if there are only numeric values up to where you start adding hyphens in cells, you could just alter your original formula like this:
=INDEX(G:G,COUNT(G:G))
This would work because COUNT only counts numeric values while COUNTA counts all non-null values (including errors BTW).
Not to take anything away from the accepted answer, but I've been working on this a bit lately in relation to this for the never-ending last row discussion and thought I'd share some potential similar solutions. These ideas are inspired by a pattern of google sheet array questions that seem to be coming up more often. I am also intentionally using different ways to do the same thing just to give people some ideas (i.e. left and Regex).
Last Row that is...
Number: =max(filter(row(G:G),isnumber(G:G)))
Text: =max(filter(row(G:G),isText(G:G)))
An error: =max(filter(row(G:G),iserror(G:G)))
Under 0 : =max(filter(row(G:G),G:G<0))
Also exists in column D: =max(filter(row(G:G),ISNUMBER(match(G:G,D:D,0))))
Not Blank: =max(filter(row(A:A),NOT(ISBLANK(A:A))))
Starts with ab: =max(filter(row(G:G),left(G:G,2)="ab"))
Contains the character !: =max(filter(row(G:G),isnumber(Find("!",G:G))))
Starts with a number: =max(filter(row(G:G),REGEXMATCH(G:G,"^\d")))
Only contains letters: =max(filter(row(G:G),REGEXMATCH(G:G,"^[a-zA-Z]+$")
Last four digits are upper case: =Max(filter(row(G:G),REGEXMATCH(G:G,"[A-Z]{4}$")))
To get the actual value (which I realize was the actual question), just wrap an index function around the Max function. So for this question, a solution could be :
=Index(G:G,max(filter(row(G:G),isnumber(G:G))))

if value between 10 & 20 then display 20% of value in another cell

i want to find the percentage of the values in range. for eg : if value between 10 & 20 then display the 20% of value, if value between 20.01 & 50 then display the 10% of value.
a sheet is attached here for more clarification.
https://docs.google.com/spreadsheets/d/1HlIflx8GkoCesl2jWdoHe30PzzAbuXUQE9XGasE7Iys/edit?usp=sharing
I have added three sheets to your sample spreadsheet.
The sheet called "Erik Help - Option 1" is self-contained. See the stand-alone array formula in cell B1:
=ArrayFormula({"UPDATED PRICE"; IF(A2:A="","",IFS(A2:A<=7,9.95, A2:A<=10,11.45, A2:A<=20,A2:A*20%, A2:A<=50,A2:A*10%, A2:A,A2:A*5%))})
This formula creates a virtual array by using curly brackets { }. First, the header is placed. Then a simple IF statement checks for whether there is anything in each cell of Column A. If there is not, then Column B will be null; if there is, then Column B will check the value of each cell in Column A against the elements of the IFS function.
The second sheet, entitled "Erik Help - Option 2," relies on the third sheet, entitled "Values." This would allow you more ease in changing assigned values.
The array formula in cell B1 of "Erik Help - Option 2" is as follows:
=ArrayFormula({"UPDATED PRICE"; IF(A2:A="","",IF(VLOOKUP(A2:A,Values!A2:C,3,TRUE)>=1,VLOOKUP(A2:A,Values!A2:C,3,TRUE),A2:A*VLOOKUP(A2:A,Values!A2:C,3,TRUE)))})
This works the same as the previous formula except that instead of referencing IFS for values, this formula references the sheet "Values" with a LOOKUP.
After checking for null values, another IF statement checks to see if the lookup value from Values!C2:C >=1 (i.e., whether it is a dollar amount or a percentage):
If this is TRUE (i.e., if the corresponding Values!C2:C value a dollar amount), the VLOOKUP runs again, comparing values from 'Erik Help - Option 2!'A2:A with the values in Values!A2:A and returning the value in Values!C2:C.
If this is FALSE (i.e., if the corresponding Values!C2:C value is a percentage amount), the values from 'Erik Help - Option 2'!A2:A are multiplied by the corresponding values in Values!C2:C.
As you can see, the results from "Erik Help - Option 1" and "Erik Help - Option 2" are identical. So it comes down to preference. If you want a self-contained option and feel comfortable editing the formula itself in the future if values change, use Option 1. If you prefer the ease of changing the values in chart form, use Option 2 with the Values chart.
NOTE: In my sheets, I also applied currency formatting (Format > Number > Currency) to all cells that contain or might contain dollar values.

How can I extract the exact part of the text on the cell of google sheet when the text can change?

In a Google Sheets spreadsheet, I have the cell A1 with value "people 12-14 ABC". I want to extract the exact match "ABC" into another cell. The contents of cell A1 can change, e.g. to "woman 60+ ABCD". For this input, I would want to extract "ABCD". If A1 was instead "woman 12-20 CAE", I would want "CAE".
There are 5 possible strings that the last part may be: (ABC, ABCD, AB, CAE, C), while the first portions are very numerous (~400 possibilities).
How can I determine which of the 5 strings is in A1?
If the first part "only" has lower case or numbers and the last part "only" UPPER case,
=REGEXREPLACE(D3;"[^A-E]";)
Anchor: Space
=REGEXEXTRACT(A31;"\s([A-E]+)$")
If you can guarantee well-formatted input, this is simply a matter of splitting the contents of A1 into its component parts (e.g. "gender_filter", "age range", and "my 5 categories"), and selecting the appropriate index of the resultant array of strings.
To convert a cell's contents into an array of that content, the SPLIT() function can be used.
B1 = SPLIT(A1, " ")
would put entries into B1, C1, and D1, where D1 has the value you want - provided your gender filter and age ranges.
Since you probably don't want to have those excess junk values, you want to contain the result of split entirely in B1. To do this, we need to pass the array generated by SPLIT to a function that can take a range or array input. As a bonus, we want to sub-select a part of this range (specifically, the last one). For this, we can use the INDEX() function
B1 = INDEX(SPLIT(A1, " "), 1, COUNTA(SPLIT(A1, " ")))
This tells the INDEX function to access the first row and the last column of the range produced by SPLIT, which for the inputs you have provided, is "ABC", "ABCD", and "CAE".

Google Sheets: Query function can't copy data

I attached a sample Google Sheet data (Link).
It contains 2 sheets. The Response sheet contains the response of the Google Form. Since the Google form has a lot of repeating questions, I have to transform the data using the Query function (sheet Transformed cell B2). The query command is
=QUERY(
{
Response!E2:H,Response!B2:D;
Response!I2:L,Response!B2:D;
Response!M2:P,Response!B2:D;
Response!Q2:T,Response!B2:D;
Response!U2:X,Response!B2:D;
Response!Z2:AC,Response!B2:D;
Response!AD2:AG,Response!B2:D;
Response!AH2:AK,Response!B2:D;
Response!AL2:AO,Response!B2:D;
Response!AP2:AS,Response!B2:D;
Response!AU2:AX,Response!B2:D;
Response!AY2:BB,Response!B2:D;
Response!BC2:BF,Response!B2:D;
Response!BG2:BJ,Response!B2:D;
Response!BK2:BN,Response!B2:D;
Response!BP2:BS,Response!B2:D;
Response!BT2:BW,Response!B2:D;
Response!BX2:CA,Response!B2:D;
Response!CB2:CE,Response!B2:D;
Response!CF2:CI,Response!B2:D;
Response!CK2:CN,Response!B2:D;
Response!CO2:CR,Response!B2:D;
Response!CS2:CV,Response!B2:D;
Response!CW2:CZ,Response!B2:D;
Response!DA2:DD,Response!B2:D
},
"select * where Col1 <> '' Order By Col6"
)
However when you look at the sheet Transformed, some data in Col F (Corresponding to Response sheet Col B) didn't get transferred. How could this problem be fixed?
Thanks in advance
It is often noted that users are tempted to mix data types within a column. The query() function will give undesirable output. If a column is intended for numeric values then only numerical values must reside in that column. Date columns must only contain dates and text columns only contain text values.
This does not mean that numbers cannot appear in a text column as long as they are in a text format.
Generally, the query() function will assume the greater number of cell types in a column to be that data type. For example, if there are 100 numbers and 20 text values in the same column then a numeric value will be assumed for that column. There is a good chance the text values will just be ignored. A slight change in your formula will convert all values to text.
See if this helps
=ArrayFormula(QUERY(to_text({
Response!E2:H,Response!B2:D;
Response!I2:L,Response!B2:D;
Response!M2:P,Response!B2:D;
Response!Q2:T,Response!B2:D;
Response!U2:X,Response!B2:D;
Response!Z2:AC,Response!B2:D;
Response!AD2:AG,Response!B2:D;
Response!AH2:AK,Response!B2:D;
Response!AL2:AO,Response!B2:D;
Response!AP2:AS,Response!B2:D;
Response!AU2:AX,Response!B2:D;
Response!AY2:BB,Response!B2:D;
Response!BC2:BF,Response!B2:D;
Response!BG2:BJ,Response!B2:D;
Response!BK2:BN,Response!B2:D;
Response!BP2:BS,Response!B2:D;
Response!BT2:BW,Response!B2:D;
Response!BX2:CA,Response!B2:D;
Response!CB2:CE,Response!B2:D;
Response!CF2:CI,Response!B2:D;
Response!CK2:CN,Response!B2:D;
Response!CO2:CR,Response!B2:D;
Response!CS2:CV,Response!B2:D;
Response!CW2:CZ,Response!B2:D;
Response!DA2:DD,Response!B2:D}),"select * where Col1 <> '' Order By Col6"))

Resources