Conditionnaly counting the number of occurences in a column - excel-formula

I have a table that contains a list of people. Every person has a role (Boss, Worker, Aid) and a duty (Cleaning kitchen, Take out trash, Washing up, Day-off).
I have an other table that lists the possibles duties. The duty is refered to by a code (A,B,C,D) and in the third column there can be a 'X' that mean "this duty is to be counted" or no text at all that mean "this duty is not to be counted". A Day-off typically doesn't have an 'X'.
I want to be able to see how many Bosses, Workers and Aids are working according to what duty they have been given.
I've tried using VLOOKUP but it doesn't give me an array as an output. I tried a combination of INDEX and MATCH but I can't make it work. I'v tried using SUMPRODUCT and a combination of SUM and IF. I think I might be misunderstanding how to use array function or at least how to use the result in another formula.
A view of my Worksheet to get better visualization
Thank you in advance for you help, I'm sure the answer is simple but I can't think of it !

Try using COUNTIFS.
Presume you have named the following ranges:
Person: B12:B20
Role: C12:C20
Duty_Code: D12:D20
For working bosses: =COUNTIFS(Role,"Boss",Duty_code,"<>D")
For working workers: =COUNTIFS(Role,"Worker",Duty_code,"<>D")
For working aids: =COUNTIFS(Role,"Aid",Duty_code,"<>D")
A suggestion would be putting the criteria i.e. Boss, Worker and Aid in Cell C3, C4 and C5 on your example worksheet, and replace the hard-coded criteria in the above formulas with the corresponding cell address.

Related

Find minimum value from multiple regularly spaced columns in excel

I have the following problem I need to address:
I have quotations from multiple vendors for multiple types of products. I need to find the product wise minimum and 2nd lowest quotations. The sheet looks somewhat like this:
I want the output in the following format:
Now, the problem is that the number of vendors is 300, and using the regular formula: min(number1,number2,number3,...) is very tedious and error prone as I have to manually click each entry for each vendor like min(B3,F3,I3,... 300 entries) for product 1.
Another problem is for 2nd Lowest Quote Here, excel does not accept discontinuous array like min function. Which means I cannot enter the formula small(B3,F3,I3,2) as it gives you have entered too many arguments error in this case.
I need to find some way to get around this problem. Please help me out with this problem.
Another option in non-array formula solution
Assume your data put in A1:P5
"Minimum quote" in K3, copied across to M3, and all copied down :
=AGGREGATE(15,6,$B3:$J3/($B$2:$J$2=K$2),1)
"2nd lowest quote" in N3, copied across to P3, and all copied down :
=AGGREGATE(15,6,$B3:$J3/($B$2:$J$2=N$2),2)
Data
You could try an array formula like so:
=MIN(IF($B$2:$J$2=K$2,$B3:$J3))
Make sure you hit Ctrl+Shift+Enter. What it does is it only extracts values corresponding to the specific product using the if statement, min then finds the minimum value out of that range.
Same applies to the SMALL function, it can take a range but we must filter that range using the IF function to get only the columns we want for that product, this also requires to be an array formula by entering it with Ctrl+Shift+Enter
=SMALL(IF($B$2:$M$2=N$2,$B3:$M3),2)

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

How to sumif the vlookup value of a range?

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.

(excel) sumproduct multiplying with another sheet

i have a little problem with final formulas in one of my column. How to start. maybe i will explain what i have a then what i want.
i have an excel worksheet with 3 sheets. i want to record goods and what are these goods made of. first is sheet called Goods where is possible to put number of goods i want to make. In this case i want to make 1x sandwich1 and at the same time 3x sandwich2. i dont want make sandwich3 this time.
Second sheet is Matrix sheet where I record every good and what it is made of. This sheet is basic sheet and all other sheets take list of goods (resp. ingredients) from this sheet. Simply when i want to make sandwich1 i look at matrix and know that i need 1x1pc of egg + 1x5g of cheese. And for 3x sandwiche2 i need 3x10g of sausages.
Final sheet is called Ingredients. It is a list of used ingredients from Matrix sheet (exactly same order) to make these sandwiches. I want to fill formulas into column B which would go through one ingredient ofter ingredient and count needed amount of it. So it would look into matrix in the same row and where there is some number it would multiply with number of items from Goods sheet. The list of goods is also in the same order as in the matrix sheet.
I hope you understand now what i want and will try to help me. I think there will be SUMPRODUCT, SUMIF and maybe INDERECT functions but i am not that skilled in excel
thanks for any suggestions
You can use MMULT function here - it's an "array formula" which you need to enter in a range. You can do that like this:
In Ingredients worksheet enter this formula in B2
=MMULT(Matrix!C2:E4+0;Goods!B2:B4+0)
[I'm assuming you have a European version of Excel where ; is used to separate arguments]
Now select the whole range B2:B4, press F2 key to select formula and hold down CTRL and SHIFT keys and press ENTER. This "array enters" the formula in the range and you should now see curly braces like { and } around the formula and also the correct results.
You cannot change part of that array now, only the whole thing
Note that I'm assuming that the contents of Goods!A2:A4 will be the same as Matrix!C1:E1 and in the same order. You can extend the ranges to be as large as you like as long as that principle still holds
I suspect that this is an issue of "when all you have is a hammer, every problem is a nail". For reasons known only to you you are using a spreadsheet to solve a problem that databases were made to do. Any solution to this problem in a spreadsheet will be entirely dependent on the integrity of your data - add another column or get things out of order and it will fail.
That said, what you have in your link is effectively a pivot table and what you need is the unpivoted version of this - the instructions for getting this are here.
When you have that, you can use the various database functions in excel to get your answer.

How do I create an =IF(OR()) statement which will count the number of true/false conditional values?

My Uncle is asking me to help his police department fix their excel sheet. They track call codes in an excel sheet which looks like this:
.
Rows in the top image are individual calls which are categorized by the numbers in A-B-C 40+ (Radio Signals, bottom image) based on the subject of the call. In my example I've placed 3 call signals from row 46 in Radio Signals as well as row 49. Now what I'd like to see happen is a count of 3 in both E46 and E49.
The issue I'm having is a limited knowledge of programming Excel statements. I know there are IF statements I can use in conjunction with AND and OR statements but this seems very long and tedious. Based on the current setup of this document, could I use a more efficient method to gain a count of signals belonging to this cell?
Any help is greatly appreciated.
Assuming your list of calls is in Sheet1 column A and the comma separated list is in Sheet2, place the following formula in Sheet2:
=SUM(--ISNUMBER(SEARCH(" "&Sheet1!$A$:$A$&","," "&Sheet2!A46&",")))
Make sure to press Ctrl-Shift-Enter when entering the formula!
Using the COUNTIFS statement works well. The following formula worked like a charm for counting occurrences of multiple conditions over a range of cells.
For Cell 46-E
=COUNTIFS(A7:A39,"=37")+COUNTIFS(A7:A39,"=56")+COUNTIFS(A7:A39,"=64")+COUNTIFS(A7:A39,"=65")+COUNTIFS(A7:A39,"=70")+COUNTIFS(A7:A39,"=81")+COUNTIFS(A7:A39,"=91")

Resources