MAX + Left Function Excel - excel

I am trying to get the max value of a column based on the Left function
What I am doing is the following :
These are the results I get when i write this into column C :
=MAX(LEFT(A:A, 2))
But what I truly want is to get in column C the max value of all column A not for each cell.
So the result should be in this case 90 for all rows.
What should be the formula here?

Just another option that gets entered normally:
=AGGREGATE(14,6,--LEFT($A$1:INDEX(A:A,MATCH("ZZZ",A:A)),2),1)
Array formulas will calculate the enitre referenced array. So care should be taken to limit the number of iterations to only the data set.
The $A$1:INDEX(A:A,MATCH("ZZZ",A:A)) part of the formula does that. It finds the last cell in column A with data in it and sets that as the upper bound. So in this instance the reference range is A1:A3. But, it will grow dynamically as data in Column A is added, so no need to change the formula each time data is added.

Update 2
Here is another solution which I think is better than my original (below)
=INT(SUMPRODUCT(MAX(SUBSTITUTE(A:A,"-",".")*1)))
it can be entered as normal (just Enter)
Orignal Answer
You need numbers and arrays
=MAX(IFERROR(LEFT(A:A,2)*1,0))
Let's break this down. Multiplying by turns your strings into numbers - since Left only returns a string
LEFT(A:A,2)*1
Unfortunately this method returns #Value if you multiply an empty string by 1. You will definitely have some empty strings in the range A:A so we wrap the whole thing with an IFERROR function.
IFERROR(LEFT(A:A,2)*1,0)
Now we still need excel to treat this as an array (i.e. a whole column of numbers, rather than just one number). So we put the MAX formula in and enter it with Ctrl+Shift+Enter rather than just Enter. The result is that the formula looks like this in the formula bar
{=MAX(IFERROR(LEFT(A:A,2)*1,0))}
which would return 90 in your example, as required
Update 1
If you are using Excel 2013 or later, you can also use the NUMBERVALUE function
=MAX(NUMBERVALUE(LEFT(A:A,2)))
again, enter it with Ctrl+Shift+Enter

Related

Condensing a large formula

I was wondering if anyone could enlighten me on a way to condense/shorten this formula:
=IF(ISNUMBER(SEARCH("Kirkintilloch",B2)),"BRN01",IF(ISNUMBER(SEARCH("Tweacher",B2)),"BRN01",IF(ISNUMBER(SEARCH("Lenzie",B2)),"BRN01",IF(ISNUMBER(SEARCH("Bishopbrigg",B2)),"BRN03",IF(ISNUMBER(SEARCH("Torrance",B2)),"BRN03",IF(ISNUMBER(SEARCH("Bearsden",B2)),"BRN04",IF(ISNUMBER(SEARCH("Milngavie",B2)),"BRN04")))))))
Column B will contain an address which will be from one of these seven towns.
The reason I didn't do an IF then Lookup was that the result I want to return is not unique, I.e. Kirkintilloch & Torrance both need to return a result of BRN01.
If it's not possible to simplify this then no worries. It would just save me a lot of work in a larger piece of work with many more possible outcomes.
This is an array formula - confirm it with Ctrl+Shift+Enter while still in the formula bar:
=INDEX(Towns,SMALL(IF(ISNUMBER(SEARCH(INDEX(Towns,0,2),B2)),INDEX(Towns,0,1)),1),3)
Breaking this down:
First you need to create a named range (I called mine "Towns") that contains the array of an index, the town name and the desired return "BRN**" (you could make this a simple range and just reference that but I entered the actual array by selecting the range in formula, highlighting it and using F9 to calculate)
Now that you have this array, I use Index providing 0 for the row argument to return all rows so that I can equate against just a single column at a time.
IF(ISNUMBER(SEARCH(INDEX(Towns,0,2),B2)),INDEX(Towns,0,1))
As this is an array formula, each row is assessed individually and the results (first column when a match is found - index of the array) returned as an array, like so: {FALSE;FALSE;3;FALSE;FALSE;FALSE;FALSE}
I then use SMALL() to catch the lowest number or the first match to feed another index for the third column.

How can I get the location of a cell in Excel based on its value if it's not the first one in the column?

I know how to use index and match formulas to get the value or location of a matching cell. But what I don't know how to do is get that information when the cell I'm looking for isn't going to be the first match.
Take the image below for example. I want to get the location of the cell that says "Successful Deliveries". In this example there's a cell that matches that in rows 11 and 30. These locations can vary in the future so I need a formula that's smart enough to handle that.
How would I get the location of the second instance of "Successful Deliveries"? I figured I could use the "Combination 2 Stats" value from row 24 as a starting point.
I tried using this formula:
=MATCH("Successful Deliveries:",A24:A1000,0)
But it returns a row number of 7 which is just relative to the A24 cell I started my match at.
My end goal here is to get the value from the cell directly to the right of the second match of "Successful Deliveries".
In your formula, with no further intelligence, you can simply add 23 to adjust 7 to the result:
=MATCH("Successful Deliveries:",A24:A1000,0) + 23
You know that 23 is the number to add because you started your search on row 24.
The full answer is here:
https://exceljet.net/formula/get-nth-match-with-index-match
You use this formula:
=INDEX(B1:B100,SMALL(if(A1:A100 = "Successful Deliveries:",ROW(A1:A100) - ROW(INDEX(A1:A100,1,1))+1),2))
...where 2 is the instance you want.
Make sure to finish typing the formula by hitting ctrl-shift-enter. (You know you did this right because the formula gets curly brackets {})
HOW IT WORKS
Normally, we use INDEX / MATCH to find a value. The Index function gives you the nth value in a range, and the Match function determines which "n" is a match for our criteria.
Here we use INDEX the same way, but we need more intelligence to find that "n", since it's the second one that matches the criteria. That's where SMALL comes in. The Small function "gets the nth smallest value in an array". So we give Small the number of the desired instance (2 in this case) and we give it an array of blanks and the rows numbers of the rows we like.
We obtained the array of blanks and row numbers using the If function, asking it to check for our criterion (="Successful...") and making it return the row number where the criterion passes (=Row(A1:A100)). By using the If function as an array function (by giving it arrays and using ctrl-shift-enter) it can deliver a whole list of values.
Our final value is just one number because the Small function used the array from the IF to return just one thing: the second-smallest row we gave to it.

Excel Index to look up multiple values

I have a small data set of 2 columns and several rows (columns A and B)
I want to return each instance of codeblk 3 in a formula that is elsewhere in my sheet, (so a vlookup is out as it only shows the first instance) if it does not appear then a message to say its not there should come up.
I have the formula partially working but i cant see the reason why its not displaying the values.
My formula is as below:
This is an array
{=IF(ISERROR(INDEX($A$55:$B$70,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)),ROW(1:1))-1,1)),"No value's produced",INDEX($A$2:$C$7,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)),ROW(1:1))-1,1))}
The result that shows up is only "No values produced" but it should reflect statement B, C and D in 3 separate cells (when changing ROW(1:1), ROW(2:2) etc)
{=SMALL(IF($B$56:$B$69=4,ROW($B$56:$B$69)),ROW(1:1))} - This produces the result 68 which is the correct row.
Any ideas?
Thanks,
This is an array formula - Validate the formula with Ctrl+Shift+Enter while still in the formula bar
=IFERROR(INDEX($A$55:$B$70,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)-54),ROW(1:1)),1),"No value's produced")
The issue you are facing is that your index starts it's first row on $B$55, you need to offset the row numbers in the array to reflect this. For example, the INDEX contains 16 rows but if you had a match on the first row you are asking for the 55th row from that INDEX(), it just can't fulfil that.
EDIT
The offset was out of sync as your original formula included another -1 outside of the IF(), I also left an additional bracket in play (the formula above has now been edited)
The ROW() function will essentially translate $B$55:$B$70 into ROW(55:70) which will produce the array {55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70} so the offset is needed to translate those row numbers in to the position they represent in the indexed data of INDEX().
The other IF() statement then produces and array of {FALSE;2;3;4;FALSE etc.
You can see these results by highlighting parts of the formula in the formula bar and hitting F9 to calculate.

replace volatile OFFSET in an excel SUMPRODUCT

I'm using Frontline's solver in excel and in some models the whole process is slowed down probably due to the heavy use of the excel function OFFSET. According to my research this function is considered volatile and should be avoided. Apparently one can replace the use of offset by INDEX. What I need to offset is a vector rather than just a value, to be used in a SUMPRODUCT. Something like SUMPRODUCT(array,OFFSET(vector)). INDEX seems to only be able to output a value rather than a vector.
Attached is a screenshot of a minimal example showing what I have as a formula. The yellow and blue cells are all fixed whereas the formula is in the green cells. The value in cell B11 is 16.
So my question: How can one replace the volatile OFFSET by something that's not volatile?
You can use INDEX. Replace your function with the following
=SUMPRODUCT(B$6:B$8,INDEX($F$6:$I$8,0,1))
The INDEX function in this case returns the first column values of the area F6:I8. The 0 returns the all rows, and the 1 returns the 1st column. You probably want to replace the 1 with COLUMN()-1 so you can copy the formula across but ideally you would do this with an array formula, but that's another question.
One tip I find really useful when working with functions is the ability to highlight part of the function in the function bar and calculate just that part by pressing F9. So if you highlight "INDEX($F$6:$I$8,0,1)" and press F9 it will show you which value(s) it is using.
From https://support.office.com/en-gb/article/INDEX-function-a5dcf0dd-996d-40a4-a822-b56b061328bd
"If you set Row_num or Column_num to 0 (zero), INDEX returns the array of values for the entire column or row, respectively. To use values returned as an array, enter the INDEX function as an array formula in a horizontal range of cells for a row, and in a vertical range of cells for a column.

Using INDEX(MATCH()) to return the n'th value of a cell

I have a simple worksheet with 2 columns
I want to get all the results(on column "H") (I can get only the first occurrence,I want to know if I can get the others) that contains the value from cell G1, is that possible without a macro ? any way of doing it would be appreciated...Any ideas?
You can use ROW() and SMALL() to get those instead of MATCH() since this always gets the first match.
=IFERROR(INDEX($C$4:$C$7,SMALL(IF($D$4:$D$7=$G$1,ROW($D$4:$D$7)-(ROW()-1)),ROWS($D$4:D4))),"Null")
So, if the array $D$4:$D$7=$G$1 returns true (i.e. the value equals that in G1), you will get the row numbers of these values, in this case, you will get 4 and 6. All the other will return False.
After some processing with -(ROW()-1), the 4 and 6 become 1 and 3. those two values are what will be fed to the INDEX.
SMALL() then picks the smallest, starting with the 1st (you get 1 from ROWS($D$4:D4)) and when you drag the formula down, the ROWS become ROWS($D$4:D5) which gives 2, and SMALL ends up taking the 2nd smallest value, which is 3.
EDIT: Forgot to mention. You have to array enter the above formula. To do this, type the combination keys of Ctrl+Shift+Enter after typing the formula (edit the formula again if necessary) instead of Enter alone.

Resources