Dynamic VLookup and Sum composition finder with Excel - excel

I’m currently looking for two formulas in order to gain in efficiency. Let me develop my research.
Firstly I’m looking for a “sum composition finder”. Basically let imagine I have 5 figures and a sixth which is the sum of x of those figures.
I’m looking for a formula which could find what the figures that compose my sum are.
Here’s an example:
1) 54
2) 21
3) 20
4) 47
5) 62
Sum : 41
Here I’ve got a sum of 41 thus I want the formula to be able to find 21 and 20 which make 41. Does someone have any idea about how I could make this works ?
Secondly I’m looking for a dynamic vlookup. As you may know vlookup use an index number to take the value needed. My plan is to make a vlookup based on the name of the column thus if there is any change in the table (I.e if I’m adding a column on my table) my vlookup isn’t broken. Also I want to know if it is possible to fix a dynamic table area.
For instance if my table goes from column A to E I would like that my vlookup is able to extend to F when I’ll add a column by himself.
I hope I’ve been clear enough, feel free to ask for some more information if something isn’t clear.
Thank in advance !

You can choose the column to retrieve in a VLOOKUP by applying a MATCH function against the column headers.
     
The formula in I2 is =VLOOKUP($G2,$A$2:$Z$99,MATCH($H2,$A$1:$Z$1,0),FALSE).
Another method is using INDEX against the data grid, applying MATCH to both the row_number and column_number parameters. In the above case, this would be =INDEX($B$2:$Z$99,MATCH($G2,$A$2:$A$99,0),MATCH($H2,$B$1:$Z$1,0)). Of course, you would have to get the formulas out of the way of the expansion area in order that you do not receive circular references.
Addendum: I've modified the formulas originally supplied to demonstrate expandability.

Related

Use VLOOKUP as criteria inside COUNTIFS

After years of using this community, I have a question that I can't find an answer to. I hope you all can help!
I am trying to get a count of the number of "Grounded" items that each individual is overdue for. My screenshot (Count Tracker) shows a very condensed version of what I'm working with. Columns A-C is my large (15,000 rows) data field that is imported from an external source. In columns G-H I have listed each possible task (about 100 rows) and the type (Grounded and Non-Grounding plus many others). Column F is where I am trying to get the count.
My formula in F9 currently uses COUNTIFS to get a count of the instances in the large array that equal E9 ("Smith" in this case) and where the due date in the large array is less than or equal to the current date in F8. What I can't figure out is how to also add to count the Tasks in the large array where the task type in Column H equals "Grounded". I tried VLOOKUP, but it seems it doesn't like it and tells me there is a problem with the formula. It doesn't work, but here's the general idea of what I'm after:
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,VLOOKUP($B$2:$B$7,$G$2:$H$4,2,FALSE),"=Grounded")
With how the data is currently presented, Smith should have a count of 1 and Jones should have a count of 0. I have a feeling that this is more simple than I'm making it to be, but I can't figure it out. I am using Excel 2016.
Hopefully I explained the problem well enough. Thank you for your assistance.
With Excel 2016 I'd say MMULT() is a good alternative here:
CSE-Formula in F9:
=SUM((A$2:A$7=E9)*(MMULT((TRANSPOSE(G$2:G$4)=B$2:B$7)*(TRANSPOSE(H$2:H$4)="Grounding"),ROW(G$2:G$4)^0))*(C$2:C$7<=F$8))
You could add a fourth column that stores whether that Task is Grounded
The formula for D2 would then be:
=INDEX($H$2:$H$4,MATCH(B2,$G$2:$G$4,0))
Modify your CountIfs formula to use this new column as a criteria
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,$D$2:$D$7, "Grounded")
Try this Sumproduct+Vlookup formula without helper solution, and can work for your Excel 2016
In F9, formula copied down :
=SUMPRODUCT((A$2:A$7=E9)*(VLOOKUP(T(IF({1},$B$2:$B$7)),G$2:H$4,2,0)="Grounded")*($C$2:$C$7<=$F$8))

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:

Sumproduct or Countif on a 2D matrix

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....

Deconstruct Excel Formula To Get Result Without Trying Values

I need to deconstruct Excel formulas so that I don't have to put values in to see what the result is. I want to put in a result and get a values. I know this is difficult given with multiple variables the answer could be different. I'm looking for more of a theory or method to use to so that I don't have to hunt and peck for answers.
This is my simplified sheet.
A B C Formula for column C
(Row 1) 25 10 (=IF(B1<15,5,10))
(Row 2) 15 22 (=ROUND((AVERAGE(B1:B3)),0))
(Row 3) 25 18 (=ROUND(((B3*5)/7),0))
Total 50 (=SUM(C1:C3))
For example, I want to come out with a total of 48. How would I go about working backwards so I didn't have to put a different number in column B to try and get the answer I am looking for, in this case, 48?
Have you tried Goal Seek, the disadvantage is it will only change 1 cell.
Using the Solver will change all three cells, but you then need to set constraints on the cells in column B.

Excel: Sum a range of cells if a related key is in a range of values using a formula

I'm trying to return the sum of a range of cells if an associated value is in a range of values used as filtering conditions. For example, using the following data table:
Keys Values
A 500
B 300
C 600
D 20
A 150
C 600
and the following list of keys to be summed:
Sum Keys:
A
D
I'm looking for a formulaic way to return 500+20+150 = 670.
I know you can use multiple SUMIFs, but the number of keys will change based on what the user wants to filter on, and writing enough SUMIFs to cover the max realistic cases (like 10ish) seems excessive, and I feel like there must be an easier way.
In my head, the formula would look something like this:
=SUMIFS(Values, Keys, OR(Sum Keys), ...(optional other conditions))
I realize that this is an easy VBA problem, but I'm trying to avoid that because the spreadsheet will be audited by people with varying (or no) VBA knowledge. Also, adding an indicator column to the data to show if the key is in the Sum Keys range isn't realistic because there will be multiple tabs summarizing the data, each with their own filters on Key
Any help is appreciated, though I realize this may be impossible without VBA. Please let me know if more information is needed.
Thanks!
EDIT: Thanks barry houdini for the answer! See the comments of his post for the general solution for summing based on multiple ranges of acceptable criteria.
You can use a formula like this
=SUMPRODUCT(SUMIFS(Values,Key,Sum_Keys))
If Sum_Keys has 4 values then the SUMIFS formula returns a 4 value "array" (one for each Key in Sum_Keys) so you then need another function to sum that array. I use SUMPRODUCT because it avoids the need for "array entry".
You can add more conditions in the usual way, e.g.
=SUMPRODUCT(SUMIFS(Values,Key,Sum_Keys,Dates,Specifc_date))
If you want to sum items in accordance to filter conditions, consider using the
=SUBTOTAL()
worksheet function. It is the tool to handle this task.

Resources