I'm not sure how to explain what I am trying to achieve so I will start with the data I am working with:
1) A table that lists IDs corresponding to Games. Each game has several IDs.
2) A table that lists IDs and $ Earned on those IDs.
In another table, I have the list of games and want to return the sum of $ Earned on those games:
Tables 1,2,3
I was trying to do this with a combination of a SUMIF and VLOOKUP formula but I can't seem to find a way to do that because the VLOOKUP returns a value rather than a range. What I want to do is sum a sum_range ($ earned) if the lookup value of the range (game corresponding to the code) is a match.
I could simply add a column to the second table that returns the game of that code with a VLOOKUP. But the problem is that this would need to be done in a very large number of sheets, and with each time the new data is received.
Hopefully that made sense and thank you in advance for any help I can get!
Cheers,
Maria
Well this may be a bit of a cheat. if you look at your game code, you are either looking for basketball or baseball. So we could do a sum if the code contains one of those words.
If case sensitivity is important
=SUMPRODUCT(--(ISNUMBER(FIND("Basketball",B2:B16)))*C2:C16)
or if case sensitivity is not important
=SUMPRODUCT(--(ISNUMBER(SEARCH("Basketball",B2:B16)))*C2:C16)
B2:B16 would be your code in table 2
C2:C16 would be your $ earned column in C2
The formula would be placed where the ? cell is beside big win Basketball.
updated option for keyword
So if you are not looking for just baseball or basketball, but the entire string of the key words that you are looking for the total for, you could use the following provided the words in table three form part of the code when the spaces are removed.
=SUMPRODUCT(--(ISNUMBER(FIND(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
or
=SUMPRODUCT(--(ISNUMBER(SEARCH(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
This assumes the keyword your are looking for in the code is in B19. The substitute function removes the spaces to match your code.
In the second table add a (hidden) column, where you perform a VLOOKUP in the first table of the Code, retrieving the Game name.
Now you have something to base your SUMIF on: the value in the additional, hidden column should match the Game you have in your summary.
Related
I'm trying to use VLOOKUP to match activities with product codes, but run into an issue since VLOOKUP always returns the first match. I did a mockup below to describe my issue. To the left, I have a table with activity names and product codes.
To the right, in column G, I want to, based on matching activity names in column F with activity names in column A, assign the activities product codes from column B.
When I use VLOOKUP, it only matches with the first activity name and give all the activities with the same name the same product codes. I need them to get different product codes even if they have the same name. I want my function to "take the next one" on the list, when the first one is taken.
Should I try to use another function to solve this? Is it impossible with VLOOKUP? My 'real' document has like 2000 rows, and the solutions I found on Youtube was not good to scale.
Thanks in advance. I'm new to here so if I should clarify my question in any way, feel free to tell me.
If the raw is around 2,000 rows, you can use a nested index match with helper columns.
Add a rank in column C with the formula =COUNTIF(A2:$A$2,A2)
Then apply the same ranking in your output part as well (Ensure Activity Name is sorted so that the formula works), Output rank formula =IF(J2=J1,I1+1,1)
Formula that lists out the Product Code {=INDEX($B$2:$B$3190,MATCH(I2,IF($A$2:$A$3190=J2,$C$2:$C$3190),0))}
This is an array formula, you get the curly brackets by hitting control+shift+Enter instead of just Enter upon keying in the formula
If you are using excel 365, you can use UNIQUE formula.
=UNIQUE(A2:B18)
I'm looking for a way to insert a column based on two criteria, as illustrated below. I have a main table with one row per company, and I want to add a column to this with the city names. However, the lookup table has two rows for some companies - one for "small" and one for "large". I'm only interested in retrieving the cities for companies that have size value "small".
I know that I can achieve this with =SUMIFS if the content of the column was a number instead of text. However, with the cities column consisting of text, I don't know how to proceed. I'd ideally like a solution where I don't have to use a helper column.
Edit: this is just an example of my data. I have hundreds of rows,the duplicate answer suggested uses INDEX/MATCH which requires me to give the exact cell location of each condition. This is not the case in my data.
There are a few solutions that I usually use for these tasks. They're not elegant i.e. not a 2-criteria look-up per se, but they get the job done.
Going by your data structure, you have these choices:
Sort your lookup table by size-company, with size in descending order. Thereafter, it's a straightforward vlookup since your big companies are seggregated from small ones.
Build a new key consisting of company-size i.e. CONCAT(company,size) and do the vlookup based on this key.
It's not possible with VLOOKUP. Look my solution in the picture using a array formula.
Solution using array formulas
Formula in F2: =INDEX($C$1:$C$6;SUM(IF(E2=$A$2:$A$6;1)*IF($B$2:$B$6="small";1)*ROW($C$2:$C$6));1)
Ps: don't forget to confirm the formula with Ctrl+Shift+Enter.
Multi-column lookups are certianly possible but not using VLOOKUP. You'll need to use INDEX and MATCH. This becomes pretty complex as it combines array formulas with boolean logic. Here's a nice explanation.
https://exceljet.net/formula/index-and-match-with-multiple-criteria
For your example, assuming Desired Result Company is in column I.
=INDEX($F$4:$F$5,MATCH(1,(D4:D5=I4)*(E4:E5="small"),0))
I am not an expert in Excel but I have been using the format.
I am trying to make a roster of my staff in Excel sheet using formulas.
The 1st sheet I have uses the row name TIME as a priority and fills other columns with staff names.
Now in the 2nd sheet, I want to use a formula in each staff ROW and the column automatically fills with the TIME at each name.
Please help me if possible.
Thank you.
Use INDEX / MATCH combo. Something like this:
=IFERROR(INDEX(Sheet1!$B$3:$B$9,MATCH($A2,Sheet1!C$3:C$9,0)),"OFF DAY")
Syntax:
=INDEX(rng,index_number) — returns the value based on the index number
=MATCH(lookup_value,rng) — returns the relative position of the lookup value
=INDEX(rng,MATCH(lookup_value,rng)) — we know all the arguments except for one — index_number. Since the output of MATCH function is the same as the index_number, we're going to substitute the index_number with MATCH function.
You can almost think of the INDEX/MATCH combo as:
=INDEX/MATCH(rng,search_value)
=IFERROR(value_or_expression_to_evaluate,value_to_return_if_error) — and finally, we're going to wrap our formula with this one, which will return a value if there is no match, which means, in your example, employee is on-leave, on a rest-day, or whatever. Can be =IFNA, too.
Now, to return all values with multiple matched lookup_value just like in your example, where "Tam" have two shifts on Monday, you may use a trailing number with employee names, i.e. "Tam1" and "Tam2" to indicate the number of shift in a given day. Or you may also use a combination of COUNTIF function (to count the number of shift of "Tam") and CONCATENATE to join the results together so that the output is gonna be: 630-1430 / 1230-2200. There are many ways to do it depending on your requirement.
Hope this helps..
I'm trying to find a formula that can help me in a problem.
This formula should SUM (or work) with every cell that is near (always on the left) a cell that has the same name. Like below:
Consider every capital letter as a "recipe" and every lowercase letter as an "ingredient". To the left of every ingredient there's a number that indicates the amount of ingredient needed in that recipe.
At the left of the table there's the list of the ingredients.
Using COUNTIF i can know how many recipes have the same ingredients, but i'm searching something to sum (or multiply, it's the same once i understood the process) every left value of the same ingredient.
As you can see i can't use SUMIF (or SUM(FILTER()) ) since for example the element "b" can be found on the 3rd and 5th column and they're not on the same column.
I tried to use INDEX() and MATCH(), and could've used also LOOKUP(),VLOOKUP(),HLOOKUP(), but as you can see there are multiple instances of the same element, and the formula returns me only the same value (Also using ROW()-1 doesn't work for the multiple elements).
Now with this little table i can calculate the numbers easily (e.g. i know that element "a" is needed 2+3+2=7 times) but since the real table has 600+ elements between "recipes" and "ingredients" I wondered if there was a way to do this.
I'm working on OpenOffice but I have no problem on using Excel.
Thank you for your answers.
Are you looking for something like this?:-
=SUM(IF(ISNUMBER($B$2:$F$7),$B$2:$F$7)*($C$2:$G$7=I7))
Must be entered as an array formula using CtrlShiftEnter
I'm working on data from a population of people with allergies. Each person has a unique ExceptionID, and each allergen has a unique AllergenID (451 in total).
I have a data table with 2 columns (ExceptionID and AllergenID), where each person's allergies are listed row by row. This means that the ExceptionID column has repeated values for people with multiple allergies, and the AllergenID column has repeated values for the different people who have that allergy.
I am trying to count how many times each pair of allergies is present in this population (e.g. Allergen#107 & Allergen#108, Allergen#107 & Allergen#109,etc). To keep it simple I've created a matrix of 451 rows X 451 columns, representing every pair (twice actually because A/B and B/A are equivalent).
I somehow need to use the row name (allergenID) to lookup the ExceptionID in my data table, and count the cases where that matches the ExceptionIDs from the column name (also AllergenID). I have no problem using Vlookup or Index/Match, but I'm struggling with the correct combination of a lookup and Sumproduct or Countif formula.
Any help is greatly appreciated!
Mike
PS I'm using Excel 2016 if that changes anything.
-=UPDATE=-
So the methods suggested by Dirk and MacroMarc both worked, though I couldn't apply the latter to my full data set (17,000+ rows) because it was taking a long time.
I've since decided to turn this into a VBA macro because we now want to see the counts of triplets instead of pairs.
With the 2 columns you start with, it is as good as impossible... You would need to check every ExceptionID to have 2 different specific AllergenID. Better use a helper-table with ExceptionID as rows and AllergenID as columns (or the opposite... whatever you like). The helper table needs a formula like:
=COUNTIFS($A:$A,$D2,$B:$B,E$1)
Which then can be auto-filled. (The ranges are from my example, you need to change them to your needs).
With this helper-matrix you can easily go for your bigger matrix like this:
=COUNTIFS(E:E,1,INDEX($E:$G,,MATCH($I2,$E$1:$G$1,0)),1)
Again, you can auto-fill with this formula, but you need to change it, so it fits your needs.
Because the columns have the same ID2 (would be your AllergenID), there is no need to lookup them because E:E changes automatically with the auto-fill.
Most important part of the formulas are the $ which should not be messed up, or you can not auto-fill it.
Picture of my self-made example (formulas are from the upper left cell in each table):
If you still have any questions, just ask :)
It can be done straight from your original set-up with array formulas:
Please note that array formulas MUST be entered with Ctrl-Shift-Enter, before copying across and down:
In the example pic, I have NAMED the data ranges $A$2:$A$21 as 'People' and $B$2:$B$21 as 'Allergens' to make it a nicer set-up. You can see in the formula bar how that looks as a formula. However you could use the standard references like this in your first matrix cell:
EDIT: silly me, N function is not needed to turn the booleans into 1's and 0's, since multiplying booleans will do the trick. Below formula works...
SUM(IF(MATCH($A$2:$A$21,$A$2:$A$21,0)=ROW($A$2:$A$21)-1, NOT(ISERROR(MATCH($A$2:$A$21&$E2,$A$2:$A$21&$B$2:$B$21,0)))*NOT(ISERROR(MATCH($A$2:$A$21&F$1, $A$2:$A$21&$B$2:$B$21,0))), 0))
Then copy from F2 across and down. It can be perhaps improved in technique with sumproduct or whatever, but it's just a rough example of the technique....