How to index and make multiple matches across multiple columns in excel? - excel

I have a spreadsheet that looks like this:
Animal Where Quantity
Giraffe Wild 22
Lion Zoo 87
Tiger Zoo 56
Giraffe Zoo 15
Elephant Wild 94
Tiger Wild 47
Lion Wild 45
Elephant Zoo 12
Tiger Zoo 48
I need to return all quantities of Tiger, but only the ones in a Zoo, and I need to list those quantities on different cells in a column. I should be able to easily change the query from Tiger to any other animal.
Output should looks something like this:
Get the quantities of Tigers that live in a Zoo:
Tiger
56
48
Get the quantities of Lions that live in the Wild:
Lions
94
Can anyone help me figure this out?

misunderstood question
so you are going to have two cells somewhere that are going to represent your criteria. Lets call it cells D1 for animal type and cell D2 for location.
You are then going to use a combination of the following formulas: INDEX and AGGREGATE.
Lets start with AGGREGATE. Use it to build a list of row numbers that match the criteria your a looking for.
AGGREGATE(15,6,ROW(range of the first column of your table)/((range1=criteria1)*(range2=criteria2)*...*(rangeN=criteriaN)),row(A1))
15 tells AGGREGATE to generate a list sorted in ascending order.
6 tells AGGREGATE to exclude any errors from the list.
ROW() gives us the row number we are working with dividing by the criteria will only allow results where all criteria are true to be a valid list entry. Any False results will result in a divide by zero error and thus
exluding the ROW() from the list of results.
ROW(A1) tells AGGREGATE to return the Nth number in the list. so ROW(A1) will act as a counter as the formula is dragged down. It will increase by 1 for each row its copied to.
A couple of important things to note. AGGREGATE performs array like calculations. As such avoid full column references within the aggregate function. Large ranges within an array calculation can slow down your computer. Marke sure you lock your reference ranges with $ to prevent them from changing as you copy unless it is something you want to change such as row(A1)
So now you know how to get a list of row numbers for the answers you want. You now want to embed this information into an INDEX formula:
INDEX(A:A,AGGREGATE(...))
Repeat this for each column of information you want to pull updating the A:A part for where you want to pull the information from.
Proof of concept
in the the image I wrapped the whole formula in an IFERROR function to display "" when nothing is found. Handy for when you copy down more rows than there are results.

Related

(Excel) How to return column header of the nth highest values with formula

Given a table like this one below:
David
Mike
Lisa
David
50
10
40
Mike
0
50
50
Lisa
10
40
50
I'm trying to come up with a column of formulas and information that will automatically rank and label. See below for a correct output example.
Chosen Row ->
Mike (this cell is defined by the user)
Rank
Number
Mike
50
Lisa
50
David
0
Basically the user should be able to change the top right cell and have the rest of the table automatically adjust based on that input.
Here, the user input "Mike" into the cell, so the formulas should look into the row labeled "Mike" (with the values 0, 50, and 50 in that order) and tell me a list of the highest scoring column names, along with their scores.
The only thing that is tripping me up is integrating something into the formula that makes it skip names it has already put into the rank list. As you can see, there are 2 scores of 50 there.
There is a page for this on Microsofts website on dealing with ties, but I don't fully grasp their example where they use Countif, so I have not been able to translate it over for my purposes. They also use rank numbers to the left of the names in their example, but I'd prefer that not be necessary if possible. I don't mind writing the cell formulas by hand if auto-fill doesn't help me with certain aspects.
I know there is a way to accomplish this. I've played with the formulas and did a lot of research. I've just about resorted to coding it all in VBA, but I feel like that would be far more work. At this point I'm so close, I feel like I'm just missing one critical element.
If one has the dynamic formula in Office 365 then we can use SORT:
=SORT(CHOOSE({1,2},TRANSPOSE(B1:D1),TRANSPOSE(INDEX(B2:D4,MATCH(H1,A2:A4,0),0))),2,-1)
And Excel will spill the results correctly.
For older we need two formula:
First get the values in order:
=LARGE(INDEX($B$2:$D$4,MATCH($H$1,$A$2:$A$4,0),0),ROW(ZZ1))
Put that in H2 and copy down.
Then we need to reference those value to get the correct name:
=INDEX($B$1:$D$1,AGGREGATE(15,7,(COLUMN(INDEX($B$2:$D$4,MATCH($H$1,$A$2:$A$4,0),0))-MIN(COLUMN(INDEX($B$2:$D$4,MATCH($H$1,$A$2:$A$4,0),0)))+1)/(INDEX($B$2:$D$4,MATCH($H$1,$A$2:$A$4,0),0)=H2),COUNTIF($H$2:H2,H2)))
Put that in G2 and copy down.
I made in excel 2016, but I think it works in all versions. First I created a Rank, then I used the Index function. Download the file here:
https://1drv.ms/x/s!Apn_2zN0NfqFhWT-OdNazVTlxI2n?e=WsZLuH
Code for Rank using array formula:
=MATCH(LARGE(INDIRECT("B"&$K$1&":D"&$K$1)+COLUMN(INDIRECT("B"&$K$1&":D"&$K$1))/100000,ROW()-2),
INDIRECT("B"&$K$1&":D"&$K$1)+COLUMN(INDIRECT("B"&$K$1&":D"&$K$1))/100000,0)

Indirect index and match problem formula in different named tables

I have a cell where I want to get the tax% based on a criteria
Coming from "Taxes", depends on manufacturer country, year of release and car type
I've tried to use search and index and its not working at all, I need the cell to check values in the manufacturer country, year of release and car type use these inputs go to the Taxes sheet and get the value
Before I start, I should come clean and say I am an evangelist for the OFFSET() function, and a mortal foe of INDIRECT().
Let's assume that the number of vehicle types (TRUCKS, SEDANS, ....) is the same for each country, ie 8. (If its not then that can be worked around with a bit more effort). You could put this number in a cell somewhere and use it when you need the number of types.
Also, let's say the first column in your screenshot is column A. And that the cell A1 contains "China".
Let's say we are looking for the tax rate in 2009, for SEDANS in France.
Function 1:
=MATCH("France",$A:$A,0) will return 14 (if I have counted correctly)
... ie cell A14 contains the word "France".
On the assumption that the years are the same for all countries we can use any of the header rows to find the right column.
Function 2:
=MATCH(2009,$3:$3,0)-1 will return 8 I think.
If your years are just strings of text, then replace 2009 with "2009".
Because your Types are not in the same order in each table (why?) we need an extra step.
Function 3:
=MATCH("SEDANS",OFFSET($A$1,(Result of f1) -1 + 3,0,8,1),0) should return 3.
What is the maths in the OFFSET function? I need to go down (14-1) rows from cell A1 to get to "France". From there I need to go down another 3 rows to get to the first of the list of Types, and there are 8 types to search in. I'm then looking at a range of cells which is 8 rows x 1 column.
Now you can extract your tax rate, using
Function 4:
=INDEX(OFFSET($A$1,(Result of f1) -1+3,1,8,100),(Result of f3),(Result of f2))
(I've put 100 as I don't know how many columns of years you have. You could use something like =COUNTA($3:$3)-1 if there was nothing else in the 3rd row after the last date).
I would put the results of each function in a cell while you test this. Once you are happy that each step is working correctly you can nest all the various functions together, or alternatively just put some extra columns on the right hand side of your results table, which you can Hide if you want to.
EDITED: To add some $ on cell references to lock the "origin" of the data.
If your tax tables are real Tables, each NAME'd with the name of the respective country, you can use something like:
=VLOOKUP(H13,INDIRECT(H12),MATCH(TEXT(H14,"0"),INDIRECT(H12 & "[#Headers]"),0))
where
H12 contains the name of the country
H13 contains the Type of vehicle
H14 contains the Year
eg:
You'll need to adapt this to your real ranges, but this provides an approach.
I'd suggest using dropdown lists (from Data Validation) in H13:H14 in order to avoid typos.
If you want to avoid using Tables and also the volatile functions OFFSET and INDIRECT (because if you have a lot of volatile functions they can impair performance of your worksheet) you can try the non-volatile, but longer and more obscure:
=VLOOKUP($H$13,INDEX($A:$A,MATCH($H$12,$A:$A,0)):INDEX($D:$D,LOOKUP(2,1/($A:$A<>""),ROW($A:$A))),$H$14-2000,FALSE)
In the above, you'll have to make adjustments
Assumptions are:
The country name is above the relevant tax table
Tax table starts in Column A
Change references to Column A if it does not start there.
Change the reference to Column D to the last column of your tax table (or even further if you will be expanding it).
The Year columns are labelled the same for all countries (eg: consecutive years starting at 2002)
$H$14-2000 calculates the column argument for the VLOOKUP function.

INDEX MATCH with multiple look ups

I am making a pricing guide and need the cell to match the product, with the respective price.
So if I need 1oz of Four Roses Bourbon, it would first look up "four roses", then find the cost of 1oz.
Currently my formula looks like this,
=INDEX(Spirits!$F$3:$F$200,MATCH($F$3,Spirits!$A$2:$A$200,0)-1,1)
but it only pulls from 1oz, and I need it to pull from however many ounces are needed. So if I needed it to pull the correct amount if I upped it to 2oz, then this formula wouldn't work.
(The -1,1 is because this formula pulls from a drop down list and it was always one row off)
Thank you!
Here is one way to do that:
PriceTbl refers to: A3:I6
Spirit refers to: B11
Size refers to: B12
The formula is:
=VLOOKUP(Spirit,PriceTbl,MATCH(Size,INDEX(PriceTbl,1,0),0),FALSE)
Match determines which column to use
Index with a column value of 0 will return the entire first row as an array.
You will need to adjust your references to suit.
Note that, as you have in your example, the oz quantities are expressed as text strings and not as numbers.

Excel: Sumif Multiple Columns based on the same Criteria

So I am trying to create a spreadsheet at allows a character in game to total the party inventory.
I am trying to sumif multiple columns based on the same criteria.
So say I am trying to sum all the rope they have.
In column A is the Item descriptions
In columns B-E are the different totals for each party member (one column per person)
Each party member has 50 rope, so I am expecting 200 rope.
I have used this formula:
=SUMIF(A:A,"Rope: Hemp",B:E) and it is only returning 50 as a value, If I utilise cell values (A1:A100 etc.) it returns a value of Zero.
I have been told that Sum Product could works so I also tried that:
=SUMPRODUCT((A1:A100="Rope: Hemp")*(B3:E100)) and I still get the incorrect result.
What am I doing wrong?
EDIT:
Here are some photos.
Here is my Raw Data. As you can see I have the inventory and tallies, when you look at rope it says 150, and this was calcualted by summing the B to E cells, however as the list is going to move and grow I thought SUMIF would be better.
As stated above, I have used a SUMIF making the range Columns B through E, and it only returns a value of 50 (I'm assuming Column B)
so came up with this:
=SUMIF(A3:A40,"="&J17&"",B3:B40)+SUMIF(A3:A40,"="&J17&"",C3:C40)+SUMIF(A3:A40,"="&J17&"",D3:D40)+SUMIF(A3:A40,"="&J17&"",E3:E40)
Which works, but I can only assume that sumif only work with ONE target range... And I tried curly brackets as well...
So, I did also use cell J17 for the object you are looking for, so you can drag it down, the "*" will find all occurences of "Rope: Hemp", or "Rope: Nylon" etc. I get a total of 150 as there are only 3 characters with rope...
Hope it helps. Someone else may have a better / neater suggestion!
I just tested it by entering Rope, rapier and rations into J17 and got the results I expect.
Image of spreadsheet:

IF 25% match or more, sum up values

Is there a way to use a formula to get excel to look at values and determine if they have atleast a 25% match then to add their values. Kind of like a vlookup and IF function combined but I am not sure how to do the 25% part. The reason I ask this is because I have a data set with Company names that are the same company but they are all typed in differently so excel recognizes them as separate companies. For example:
Company: Value
XYZ Incorperated 25
XYZ Company 40
XYZ 12
ABC INC. 39
ABC inc. 10
ABC COMPANY 15
I need it to realize that all the companies with "XYZ" are the same and to add all their values. Same goes for "ABC". Again, I am not entirely sure it is possible but I haven't been able to find a way to get excel to sum it up for me.
Side note I could do it manually but the problem is that the data set is always changing so I need a formula that can recognize the similarities in each cell.
Try using Sumproduct. I am assuming that all of your Column A will start with the company name. (I.e. there won't be 'Company XYZ', only 'XYZ [...]'. If this isn't always going to be the case, let me know.
Does this work? I assumed Company is Col. A, Value is Col. B - going to row 7.
=SUMPRODUCT(--(LEFT($A$2:$A$7,LEN(E2))=E2),--($B$2:$B$7>=25),$B$2:$B$7)
So, if a cell has "XYZ" as company, and the "Value" for that row is 25 or greater, it'll add together. The XYZ cell equates to 65, and you can see the ABC correctly calculates 39.
edit: Here's a screenshot, using named ranges to maybe make it easier to see what goes where in the formula:
Yes try SUMPRODUCT it is great. Very simply, it look through column B which is the company names to match the left three characters in the name to what ever you type in cell E3 and sums the values in the value column.
=SUMPRODUCT(--(LEFT(B4:B9,3)=E3)*1,C4:C9)

Resources