Find a value that corresponds to another - excel-formula

I have set up a table that includes values for products used in several industries. I have used the COUNT function so I can find the industry that uses the greatest number of products.
Now I want to identify the cell in the column of COUNT results that has the maximum value and return the name of the corresponding industry from the left hand column.

Use MAX to identify the highest count amongst the counts and then use that to VLOOKUP the matching industry. For VLOOKUP to work the count must be left of the industry. If you can't arrange this, you can accomplish the same thing with a combination of INDEX and MATCH.
For example, if you have counts in A1:A6 and industries in B1:B6, you can find the industry with the most counts with
=VLOOKUP(MAX(A1:A6),A1:B6,2,false)

Use =MAX to find the maximum value, then =MATCH to find which row the maximum value is in and =INDEX to find the name of the corresponding industry. Since left hand column =VLOOKUP is unlikely to suit.

If you have the count value all figured out and you know what sheet that they are located within in your workbook, you can use something similar to the following:
Using the following data:
Col A Col B
Industry ProductVal
A 11
B 45
C 22
D 9
E 8
F 12
Assuming that you already have assigned 45, the largest value in column B to a cell, you can substitute the 45 below for that cell.
=INDEX(A2:B7,MATCH(45,B2:B7,0),1)
The above excel formula will return the value of B which is the value to the left of the "match value" of 45. A brief explanation is you define the index as the entire set of columns that are bounded on the left by the industry and on the right by the value. In the above example that was A and B. The Match then reads, find the value of 45 in the column B from row 2 - row 7 and match the first exact match (that is what the zero is for) and the 1 from the index function indicates that you will return the value that is in the first column (reading left to right) of the INDEX array A2:B7.
You can find an explanation of index here, an explanation of match here
and a nice explanation of using them together here.
Best of luck.

Related

How to get maximum number and name from 2 columns? (Excel)

I have this (example):
Luffy 320
Coby 350
Zoro 180
Now I want to show the max from this info, with number and text (in seperate cells) like this:
col 1 col 2 col 3
1st 350 Coby
2nd 320 Luffy
3rd 180 Zoro
The 2nd Column no problem with the MAX() formula.
For the 3rd column to get the text I've tried the MAX(...) and INDEX(...) formulas but nothings working ...
Can anyone help me?
You first need to get which value is the largest, second largest and so on.
You can use the function LARGE(range, n) for this.
So in your col 2 use this formula:
=LARGE(B:B,1)
=LARGE(B:B,2)
=LARGE(B:B,3)
Assuming B is the column with the values.
Then we need to match this value and get the name
=INDEX(A:A,MATCH("the above calculated cell",B:B,0))
With the above calculated cell I mean the LARGE function cell. And assuming column A is the column with the names.
This should give you a dynamic table that will update when values or names change.
I'm not sure how you manage to get that column 2 using MAX formula since it only outputs the largest number of the inputs and thus can't output 2nd and 3rd position.

Excel: Finding next equal match in column

I've googled for a solution to my problem for days and I just can't seem to get my head around how to do this.
I have 28 chickens and I track the eggs each one lays each month. My Excel sheet looks like this:
Current Egg-cel sheet
Column C is populated by the formula:
=LARGE($A$2:$A$29,$B1)
I'm using column B to increment the LARGE function
I want column D to populate with which chicken number laid the quantity in column C.
Obviously INDEX MATCH or VLOOKUP returns the first match for all equal values. How do I find the the next match? i.e.
Egg-cell sheet 2
I've seen similar questions and solutions but I for the life of me can not get it to work.
Use this formula in D2:
=INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$29)/($A$2:$A$29=C2),COUNTIF($C$2:C2,C2)))
And drag down
If you're happy to add a few helper columns, this is a simple way to go:
The formula in column C creates a unique number by bringing together the eggs laid and the chicken number
=--(A2&"."&B2)
Column D is just your LARGE formula,
=LARGE($C$2:$C$4,B2)
Column E just gets the integer part of column D
=INT(D2)
And finally Column F gets the decimal part (chicken number) from column D
=--REPLACE(MOD(D2,1),1,2,"")

In Excel I have two columns that equal a third column but they don't equal each other. How do I get them to equal each other?

In Excel I have two columns that equal a third column. How do I get the first two to correspond to each other? Listed below is a small example. Sorry I didn't know to properly paste the Excel into this post. As you can see I have Columns A-E with the titles UPC, Barcode, RMSID, UPC and Barcode. Columns A and D are the same value of a UPC. Both B and C correspond to the UPC column or A and D. I want B and C to correspond to each other since they both share the value of A or D. So if C and D correspond to each other then B does also and I want this to show in Column E. How do I write this in Excel?
A B C D E
UPC Barcode RMSID UPC Barcode
834135001034 102432 883 892773000857 105422
892773000864 105423 884 818780010016 106487
892773000604 105421 888 892773000864 105423
892773000857 105422 900 892773000604 105421
818780010016 106487 910 834135001034 102432
ok, this looks like a straight forward Vlookup or index/ match. In E2 place the following formula:
=Vlookup(D2,$A$2:$C$6,2,0)
D2 is what you are looking up in the first column of A2:C6 where C6 is the bottom right corner of your data. the 2 tells the formula to return the value in the second column. the 0 or false tell the formula to find an exact match for what you are looking for.
you could also do this with an INDEX/MATCH combination. It tends to be preferred as vlookup only looks up information in the left most column and can only return information to the right. INDEX/MATCH does not have to line up vertically and the columns (or rows if you are doing horizontal lookups) can be in any order. I would use the following:
=INDEX($B$2:$B$6,Match(D2,$A$2:$A$6))
Match will tell you what postion from the top of the A2:A6 column the value in D2 was found. Index will then use that value to return the value in the same position from the top in column B2:B6.
When something is not found its going to spit out and error. You can deal with that error using the IFERROR function and either have it return some text to let you know, or return an empty cell with "". Here is one example:
`=IFERROR(VLOOKUP(D2,$A$2:$C$6,2,0),"Not Found")

Ranking in Excel with multiple criteria

For example, I need to create a merit list of few student based on total marks (column C), then higher marks in math (column B) -
A B C D
-------------------------
Student1 80 220 1
Student2 88 180 3
Student3 90 180 2
Expected merit position is given in column D.
I can use RANK function but I can only do that for one column (total number). If total number of multiple student is equal, I could not find any solution of this.
You can try this one in D1
=COUNTIF($C$1:$C$99,">"&C1)+1+SUMPRODUCT(--($C$1:$C$99=C1),--($B$1:$B$99>B1))
and then copy/fill down.
let me know if this helps.
Explanation
Your first criteria sits in column C, and the second criteria sits in Column B.
Basically, first it is counting the number of entries ($C$1:$C$99) that are bigger than the entry itself ($C1). For the first one in the ranking, you will get zero, therefore you need to add 1 to each result (+1).
Until here, you will get duplicate rankings if you have the same value twice. Therefore you need to add another argument to do some extra calculations based on the second criteria:
To resolve the tie situation, you need to sumproduct two array formulas and add the result to the previous argument, the goal is to find the number of entries that are equal to this entry with $C$1:$C$99=C1 and have a bigger value in the second criteria column $B$1:$B$99>B1:
you add -- to convert TRUE and FALSE to 0s and 1s so that you can multiply them:
SUMPRODUCT(--($C$1:$C$99=C1),--($B$1:$B$99>B1))
the first array is to see how many ties you have in the first criteria. And the second array is to find the number of bigger values than the entry itself.
Note you can add as many entries as you like to your columns, but remember to update the ranges in the formula, currently it is set to 99, you can extend it to as many rows as you want.
Sometimes a helper column will provide a quick and calculation-efficient solution. Adding the math marks to the total marks as a decimal should produce a number that will rank according to your criteria. In an unused column to the right, use this formula in row 2,
=C2+B2/1000
Fill down as necessary. You can now use a conventional RANK function on this helper column like =RANK(D2, D$2:D$9) for your ranking ordinals.
Very simple (or, at least, much more simpler that the one provided by the best answer) 'math' solution: do a linear combination with weights.
Do something like
weighted_marks = 10*colC + colB
then sort weighted marks using simple rank function.
It does solve your problem, bulding the ranking you need.
If you don't like to limit the number of rows or the numbers used in the criteria, Jeeped's approach can be extended. You can use the following formulas in cells D2 to L2, assuming that there are three criteria, the first one in column A, the second one in column B, and the third one in column C:
=RANK($A2,$A:$A,1)
=RANK($B2,$B:$B,1)
=D2*2^27+E2
=RANK(F2,F:F,1)
=RANK($C2,$C:$C,1)
=G2*2^27+H2
=RANK(I2,I:I,1)
=J2*2^27-ROW()
=RANK(K2,K:K,0)
The formulas have to be copied down. The result is in column L. Ties are broken using the row number.
If you like to add a fourth criterion, you can do the following after having the formulas above in place:
Add the new criterion between columns C and D.
Insert three new columns between columns I and J.
Copy columns G:I to the new columns J:L.
Copy column G to column M, overwriting its content.
Change the formula in column L to point to the new criterion.
The factor 2^27 used in the formulas balances the precision of 53 bits available in double-precision numbers. This is enough to cover the row limit of current versions of Excel.

How to return a value to the left of a table array with VLOOKUP?

I need help searching Column E for value=1 and return the value of column A for the same row. VLOOKUP isn't working because there are many columns being searched and there are several 1's in the lookup, and I couldn't seem to search just 1 column using VLOOKUP. Here's how my spreadsheet looks...
A B C D E
1 Name Weight WeightRank Height HeightRank
2 Mike 170 3 6.3 2
3 Richard 200 1 6.0 3
4 Charles 185 2 7.0 1
So I want to search column E for value=1 and return the corresponding value in column A, which in this example would search "HeightRank" for "value=1" and return "Charles"
I tried using =VLOOKUP(1,E:E,1) but that returns an error.
I tried using =VLOOKUP(1,A1:E3,1) but that returns an error.
INDEX(A:A,MATCH(1,E:E,0))
VLOOKUP doesn't work here -- it always searches in the first column of your table and returns a value of a column a given number of columns to the right.
The INDEX/MATCH combination is more flexible, letting you just choose the two columns you want. It's also easier to read (you don't have to count columns to see what it does) and it doesn't break if you insert or delete columns in between the ones you're using, which VLOOKUP does. If you use the trace-formula features, VLOOKUP also falsely implies that all the columns in between are precedents of your resulting formula. (Can you tell that I don't much like VLOOKUP? I just always use INDEX/MATCH and my life is easier for it.)
The OFFSET solution works but it's volatile, so you'll really bog down your worksheet if many cells depend on the result of your formula.
MATCH(x,E2:E4,0) returns the relative position of x in the range E2:E4. For example, MATCH(1,E2:E4,0) returns 3, because 1 is the value of the third cell in the range E2:E4.
OFFSET(A2,r,c) returns the cell r rows and c columns away from A2.
Thus you can say =OFFSET(A2,MATCH(1,E2:E4,0)-1,0) to return the value from column A corresponding to the cell in column E that contains 1.

Resources