Return max index value in vlookup - excel

I'm trying to pair a vlookup with a max function. For some reason it only returns #ref every time I try to use it though.
My sheet looks like this:
A - B - C - D - E - F - G
1...
5 - Prod5 id1 $100 $125 $155 $110 $150
6...
A:G is named buyAverages
C:G is named buyAveragesPrices
What I want to do is have a vlookup go and find a value in Col A and then return the highest value in that Col. So example:
A - B
1 - Prod5 *return highest price for Prod5
What I wrote in B1, which failed:
VLOOKUP(A1,buyAverages,MAX(buyAveragesPrices))
So how do I achieve this lookup? Everything I have found is how to use MAX for the lookup value, but nothing to use max on the returned index.

Try this
=MAX(IF(A:A="Prod1",C:G))
This is an Array Formula. i.e you have to press Ctrl+Shift+Enter

If there's only one instance of each Product then you can use INDEX/MATCH like this
=MAX(INDEX(C2:G100,MATCH("Prod 1",A2:A100,0),0))
Longer than Sid's suggestion but doesn't need CSE and might be more efficient if you only have a single match
If you have that formula in Z2, for example, you can use this version to get the location from row 1
=INDEX(C1:G1,MATCH(Z2,INDEX(C2:G100,MATCH("Prod 1",A2:A100,0),0),0))

You can have all in one cell using Vlookup and Max with a nested formula. For example at the top of the page:
A1 = Select the name of the product you want to find the max
A2= MAX(BUSCARV($A$1;$A$3:$F$11;3;FALSO);BUSCARV($A$1;$A$3:$F$11;4;FALSO)
;BUSCARV($A$1;$A$3:$F$11;5;FALSO);BUSCARV($A$1;$A$3:$F$11;6;FALSO))
It's long but you only have to type it once. With this formula we get all the different amounts in each column and then we ask for the maximum. It works if all the products are different. Change the name of the product and you'll find the MAX in the table.
Example Prod8
Prod8 41 ; If we change and you select in A1 Prod4 you'll
get 70 and so on..
Prod1 id1 100 125 155 110
Prod2 50 25 20 75
Prod3 60 65 15 90
Prod4 70 12 50 43
Prod5 100 200 80 25
Prod6 20 28 40 40
Prod7 14 43 60 80
Prod8 22 33 15 41
Prod9 65 48 50 70
Select your range accordingly.
You also could include in A1 a match code to select the name of your products..

Related

Sumif of multiple Index matches against one value

Need help regarding Excel dynamically search based sum of two columns matching from two different tables.
I have got this Table of Data Entered One Time
A B C
1 Qlty Warp Weft
2 Stpl.1 150 20
3 Cotn.1 80 60
4 Stpl.2 20 20
5 Cotn.2 20 20
6 Stpl.3 20 40
in Column A2:A6, Quality can not be duplicated, its a unique Name
The Data entry and report Table is here
A B C D E F
8 Yarn Name Sent Bags Remaining Qualty Used Warp Used Weft
9 20 800 600 Stpl.1 71 200
10 150 101 30 Stpl.2 70 30
11 40 300 290 Stpl.3 100 10
12 20 400
C9:C5000 is Returning Column, Values are calculated on the base of Column A9:A5000 (Yarn Name)
Need to Find Yarn Name (eg:) "20" in B2:B6 AND/OR C2:C6, wherever it matches, index that Quality from A2:A6
Then match the returned qualities(could be more than one) to D9:D5000 and sum the mathced results from E9:F5000
I have tried so far in C12
=SUMIF($A$9:$A12,A12,$B$9:$B12)-(SUMIF($D$9:$D12,INDEX($A$2:$A$6,MATCH(A12,$B$2:$B$6,0)),$D$9:$D12)+SUMIF($D$9:$D12,INDEX($A$2:$A$6,MATCH(A12,$C$2:$C$6,0)),$D$9:$D12))
PS:- I am using Excel 2007
If I understand correctly, then following array formula can help you:
=SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,(MMULT(--($B$2:$C$6=A9),TRANSPOSE(COLUMN($B$2:$C$6)^0))>0)*(ROW($B$2:$C$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($E$9:$E$12+$F$9:$F$12))
Array formula after editing is confirmed by pressing ctrl + shift + enter
Edit:
To calculate Warp and Weft columns separately use following array formula:
=SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,((A9=$B$2:$B$6)*ROW($B$2:$B$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($E$9:$E$12))+SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,((A9=$C$2:$C$6)*ROW($C$2:$C$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($F$9:$F$12))

Average of each entry from a column values based on unique value of another column

I have a file which looks like:
E1 32 45 + Apple
E2 54 76 + Apple
...
...
-E2 300 400 + Apple
-E1 540 760 + Apple
E1 560 600 - Orange
E2 340 440 - Orange
...
...
-E2 30 40 - Orange
-E1 20 7 - Orange
Here E for each unique value from last column can range from 1 to 100. And the last column can go till several thousand unique fruits. I want to estimate the average of difference in first E's (E1) from each unique value of last column.
E1 ((45-32)+(600-560))/2 = 26.5
E2 ((76-54)+(440-340))/2 = 61
I want the calculate E1, E2 and E3, and also -E3, -E2, -E1, where -E1 is last E in every unique entry from last column, similarly -E2 and -E3 are second and third last Es.
I tried groupby from pandas to approach this problem:
df1.groupby(str(line[4]))[line[2]-line[1]].mean()
I dont not know whether groupby is the right approach or not, and I am having hard time making a loop for this case. `

Create a list of values from a table of values and exclude certain values

I have the following Excel spreadsheet:
A B C D E F G
1 Q1 Q2 Q3 Q4 Positive values
2 Asset 1 -50 85 -90 70 85
3 Asset 2 -28 -80 -45 60 70
4 Asset 3 -30 50 55 -10 60
5 Asset 4 -20 5 -80 -15 :
6 Asset 5 35 -30 27 -98 :
7
In Cells A1:E6 I have different assets with their performance from quarter Q1-Q4.
In Column F I create a list of all postive performances of the assets using the formula from here:
Column F = {LARGE(IF($B$2:$E$6>0,B$2:$E$6),ROW(B1:E1))}
All this works fine so far.
However, now I want to exclude certain values from the list in Column F. For example I do not want that number 85 or number 70 appear in the list. Therefore, I tried to modify the formula to:
Column F = {LARGE(IF(AND($B$2:$E$6>0,$B$2:$E$6<>85,$B$2:$E$6<>70),B$2:$E$6),ROW(B1:E1))}
However, now I get 0 as result.
Do you have any idea of a formula that could solve this issue?
Create an array of 0's where 0 is equivalent to a negative number or the excluded values
($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70)
1/(… will convert that to 1's and errors
Multiply by the original to create an array of original values and errors
=1/(($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70)) * B2:E6
Use the aggregate function to get the results you want
=AGGREGATE(14,6,1/(($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70))*$B$2:$E$6,ROWS($1:1))
Fill down to get the 2nd, 3rd, etc largest
You are on the right path. Instead of using AND, a nested IF would work.
You need to create a new IF criteria for every new condition you want to test.
So if you want to exclude 85 and 70 you need to add two additional IF statements.
Formula for Column F would be:
={LARGE(IF($B$2:$E$6>0,IF($B$2:$E$6<>85,IF($B$2:$E$6<>70,B$2:$E$6))),ROW(B1:E1))}
You can read here how the formula process is: Minimum if multiple criteria
If you have data in column F and you want to extract all values that are not 70 or 85 into column G, then in G2 enter:
=IFERROR(INDEX(F$2:F$9999, AGGREGATE(15, 6, ROW($1:$999)/((F$2:F$9999<>85)*(F$2:F$9999<>70)), ROW(1:1))),"")
and copy downwards:
Note that this approach does not require the use of an array formula.

Find what range a number belongs to

Ive written a function to calculate what MARK a student gets, based on a scoring table.
Why does my function work only for A mark?
This what the excel sheet looks like
COLUMN: A B C
Student SCORE MARK
1 adsf 90 A
2 asgfd 89 FALSE
3 A 90 100
4 B 81 89
5 C 71 80
6 D 61 70
7 E 56 60
8 Fx 0 55
This is the function:
{=IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))}
I'm using {} brackets for array functions. (CTRL SHIFT ENTER)
Thank you
You're on the right track but your formula is returning an array not a single value. Wrapping the result in LOOKUP should give the desired result:
=LOOKUP("Z",IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))
This returns the last matching grade since "Z" is larger than any other text value in the range.
A simpler method is:
=LOOKUP(-B1,-C$3:C$8,A$3:A$8)
The negative signs are needed so that the lookup values are in ascending order.

Is there any range or between kind of function in Excel?

I have a table with three columns in Excel, a,b and c.
One cell has a numeric value X [say 25], I need to get the value in the c column such that X should be in between min and max column. For X=25 the value in c is "20" since X is between the min and max values for the 5th table row.
I'm looking for a range or between kind of function, but couldn't find a function with either name.
a b c
-----------------------------
min max improvements
0 1 70
2 5 60
6 10 50
11 20 30
21 30 20
31 40 10
41 80 5
You want to look up in that table of yours which improvement value is correct if some value is "25"; in this case that would mean to match line 5 of your table and return the value 20.
You are looking for VLOOKUP, e.g.
=VLOOKUP(B12;A2:C8;2)
giving
(edit: fixed stupid typo in formula and image, now giving correct result)

Resources