Finding which list (of multiple) a value is in - excel

I have several lists of general categories in different columns, with each category title in row 1 and each having several different items in rows below it. Picture for reference:
On this same worksheet I want to be able to enter any of the items (Pork, Apple, Cheese, etc.) in cell E2 (my lookup value). What formula can I put in cell F2 to have it return the header of the list that item belongs to (Meat, Fruit, Dairy, etc.)? With my current understanding of V/HLOOKUP and INDEX/MATCH formulas I believe you can only lookup values in a single row or , but here I want to be able to have a lookup array of multiple rows and columns, and have it return the value of the top row of the appropriate column.
Edit:
Here is what I have tried so far:
=HLOOKUP(E2,A1:D5,1,FALSE)
=INDEX(A1:D5,1,MATCH(E2,A2:D5,0))
I am using Excel 2016

The answer is to use SUMPRODUCT.
If your lookup value is in E2 and your formula in F2, use this formula:
=INDEX(A1:D1,SUMPRODUCT((A2:D5=E2)*COLUMN(A2:D5)))
This formula is not an array formula, and doesn't require the ctrl+shift+enter.

=INDEX(A1:D1,,MIN(IF(E2=A2:D5,COLUMN(A:D))))
Enter the formula with ctrl + shift + enter
MIN searches for the first TRUE where E2=A2:D5 and returns in which column A:D that was and returns that number for use in your INDEX.

Related

Sumif with mapping multiple the same rows

I want to write excel formula that will sumif the values based on a match of the rows. The problem is that I the cells to be matched can occur multiple times and basing on the Mapping legend they should return the sum of values.
In the yellow cells I am trying to caluclate sumif of values in range B9:B14. In formula I am using index to match the names and to return the sum of all that is assined to Item1, then Item2 and Item 3. Unfortunately, Index gives only the match with the first met not with the all that I have in mapping legend. Does Anybody has idea how to write this formula?
Here is the formula that I use (wrong) and in cell C4 and C5 is the result that should be achieved for Item 2 and Item 3:
:
Item 1 is ok because it does not have more than 1 mapping.
You can also use the following in B3 and drag down.
Enter as an array formula using Ctrl+Shift+Enter
=SUMPRODUCT(--($A$10:$A$15=IF($F$3:$F$8=$A3,$G$3:$G$8)),$B$10:$B$15)
This works because the arrays are of equal length and items appear in the same order.
You can easily accomplish this in two steps:
In H3 enter formula: =SUMIF($A$10:$B$15, G3, $B$10:$B$15). Drag it all the way down until 8th row.
In B3 enter formula: =SUMIF($F$3:$H$8, A3, $H$3:$H$8). Drag it all the way down until 5th row.
Your results should be like this:
its very simple no need to complicate with index functions.
First you need to cross ref the mapping legend with your inputs using sum-if function and then do that again to get individual values from each items.
Sumif in action
Sumif visualized
With refrence to the image put this formula in H3 to H8
=SUMIF($A$10:$A$15,G3,$B$10)
and then this formula in B3 to B5
=SUMIF($F$3:$F$8,A3,$H$3:$H$8)

IF Function/VLOOKUP Combo

So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.

Return the row number if value is between two values in excel

If I have a lookup table with a range of number (Min and Max) in two columns. ON the second sheet, it contains the numbers (1-100). And I'd like to lookup the row number from the lookup table. How can I do?
Consider:
=INDEX(A$2:A$11,MATCH(D2,B$2:B$11,1))
Assuming that Band is in the A-Column, Min in the B-Column and so on and the headers in the first row, put this in F2 and drag down as necessary:
{=INDEX($A$2:$A$11,MATCH(1,(E2<=$C$2:$C$11)*(E2>=$B$2:$B$11),0))}
Please note that you don't have to put in the {}, this indicates, that this is a array formula, so you have to enter this formula with Ctrl+Shift+Enter instead of just Enter.
If you have the data in different ranges, then you will have to adjust the ranges accordingly.
If you are interested in the row instead of the Band, then wrap ROW arround the formula, so:
{=ROW(INDEX($A$2:$A$11,MATCH(1,(E2<=$C$2:$C$11)*(E2>=$B$2:$B$11),0)))}
Again with Ctrl+Shift+Enter.
You can use index match.
Give the lookup table a name, for example "tbl"
Lets say numbers are in column G
Then you can use this formula:
=INDEX(tbl[band];MATCH(1;(G11>=tbl[min]) * (G11 < tbl[max]);0))
Tables
Formula
Reference:https://exceljet.net/formula/index-and-match-with-multiple-criteria

Get the maximum values of column B per each distinct value of column A

I have an Excel spreadsheet of the form:
A,B
X,1
X,5
Y,4
Y,11
X,7
Z,1
I would like to get the maximum value of column B for each distinct value of column A - how can I do it via pure Excel formula?
Desired result (order is irrelevant):
A,B
Y,11
X,7
Z,1
In other words, I would like Excel's version of an SQL query
SELECT A,max(B)
FROM myTable
GROUP BY A
Any version of Excel is acceptable, but I use 365 one.
Pivot tables are an acceptable approach (I currently did it with a pivot myself) but I would strongly prefer a real formula - the main goal of the question is to enhance my understanding of formula programming in Excel. No VBA
Gary's Student's answer is correct. I added a couple things.
Also, a link to the method:
http://blog.contextures.com/archives/2011/07/27/finding-min-if-or-max-if-in-excel/
A distinct list of values can be generated in a couple ways, here's one:
And here's links to a method or two for distinct lists. All with array formulas:
Ignore Duplicates and Create New List of Unique Values in Excel
Getting unique values in Excel by using formulas only
With data in columns A and B use the Array Formula:
=MAX(IF(A1:A6="x",B1:B6))
Same for "y" and "z"
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
Notice the braces in the Formula Bar
EDIT#1:
To generate the formulas automatically, first copy column A to column C.
Then use the Remove Duplicate feature in the Data tab:
Then enter the Array Formula in cell D1:
=MAX(IF(A$1:A$14=C1,B$1:B$14))
and copy down:
The formula is only entered once and then copied down!
Pivot table is the correct answer.
Select column A's title and drag it to the Row Labels section.
Select column B's title and drag it to the Values section.
Click the arrow on column B's title in the values section and choose Value Field Settings.
Select Max
Try below. Note I moved your desired output table to Columns D and E. You will not need to hard-code any values into formulas.
Data
D E
Y 11
X 7
Z 1
Formulas
E2 Formula: ={MAX(--($D1=A1:A6)*B1:B6)}
E3 Formula: ={MAX(--($D2=A2:A7)*B2:B7)}
E4 Formula: ={MAX(--($D3=A3:A8)*B3:B8)}

Vlookup to check two conditions

I am referring to below my google spreadsheet
https://docs.google.com/spreadsheets/d/1dCfShenhV2j98q5wkOXMeyWj9tlMZbaBgBqB2vAPdHo/edit?usp=sharing
I am looking to update H,I and J columns using vlook formula in way that it should match both name and date values in my data range, which in A,B and C columns
Here is the issue I am facing with normal vlookup is that I can check only name.It is ignoring the date and updating the vlooked up data on all date column.
Eg: Alpha and date 20141120 value is 10, it should fill only H3, but it is updating, H3 I3 and J3 with value 10
I really appreciate your answer on this problem!!!
you can use this formula of index and match:
=IFERROR(INDEX($A:$C,MATCH(1,($A:$A=$G3)*($B:$B=H$2),0),3),"")
paste it in the first cell of your table H3, and drag and fill to the right and then select the entire row and fill down till end.
it should work.
if error(();"") : you will get empty cells if there is no match.
this is an array formula, so press ctrl+shift+enter to calculate the formula
UPDATE: here is [the example sheet downloadable from here}(https://www.dropbox.com/s/clqxsj5j4bdk27b/indexmatch.xlsx?dl=0)
Basically you need to concatenate the results, then use a VLOOKUP on that.
I.e. insert a column between B and C, with formula "=CONCATENATE(A2,B2)"
In the range you want to update, use the column and row headings for you lookup
"=VLOOKUP(CONCATENATE($g3,h$2),$c$1:$d$3,2,false)"
You want to perform a Multiple Lookup (see this).
As indicated there, enter
=IFERROR(LOOKUP(2,1/($A$1:$A$3=$G3)/($B$1:$B$3=H$2),$C$1:$C$3),"")
in H3. Copy into H3:J5.
This avoids array formulas.

Resources