Count how many cells contain this string with lookup value - excel

I have a large table of IDs and file quality from files that pertain to that ID. There are multiple files that constitute a data point (imaging data, volumetric in manner) so there are multiple rows per ID. A sample table similar in manner is posted below.
The goal is to create a function that will count how many "good" and "bad" values are per lookup subject in the SubjID column. There are ranges I want to follow, where if >50% of the G_R_B values for that SubjID are good, than G_R_B = G, 50% is good = R, and x<50% is good = B.
I will then sort and get unique value per subject ID.
Does anyone know how to do this? I tried using VLOOKUP and COUNTIF and found ways to do it when all duplicate IDs are stripped, but I am struggling to take into account when duplicate IDs occur.
EDIT: SAMPLE TABLE TO SEE WHAT TO DO IF RANGES ARE INVOLVED (see comment)

If you can't use latest Excel formulas, you can use:
=IF(COUNTIFS($A$2:$A$7,"good",$B$2:$B$7,B2)/COUNTIF($B$2:$B$7,B2)>0.5,"G",IF(COUNTIFS($A$2:$A$7,"good",$B$2:$B$7,B2)/COUNTIF($B$2:$B$7,B2)<0.5,"B","R"))
Result:
COUNTIF used to find how many times value in B2 appears in B column.
COUNTIFS used to find how many times value in B2 appears in B column, with criteria "good" in column A
EDIT:
Updated formula according to your comment and edit:
=IF(COUNTIFS($A$2:$A$21,"good",$B$2:$B$21,B2)/COUNTIF($B$2:$B$21,B2)>0.8,"G",IF(COUNTIFS($A$2:$A$21,"good",$B$2:$B$21,B2)/COUNTIF($B$2:$B$21,B2)>=0.2,"R","B"))
Result:

Related

VLOOKUP text with two criteria

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

Using COUNTIF but not including blanks with other formula

Firstly, apologies if this is covered somewhere deep within the site, I have looked through a lot of other posts and none of the solutions have worked for me.
I'm creating a workbook for a local league I'm involved in and this is the only sticking point I'm coming up against.
In cell J55, I have the formula:
=IF(C11=H55, COUNTIF(D11, "="&E11),0)+IF(C19=H55, COUNTIF(D19, "="&E19),0)
(I've simplified this to only look at rows 11 & 19 for the purposes of this question)
So what I'm essentially saying is if the team name is equal to the corresponding name in the table, count if the scores for both teams are equal. Basically I'm trying to get the number of games that end in a draw.
So at it's core, my formula is looking for whether 2 cells are equal. This is fine, other than it is counting even if the score cells are blank.
So if you refer to the below image, in J55, I'm getting the returned value of "2". However for the values I've populated in the results (just the scores in the first game) it should be returning a value of "1".
If anybody can help in any way it would be a great help.
To count the number of Draws this formula which performs array like calculations will count the number of occurences where where the team name in H55 is equal to the team name in column D or F and when the scores in column D and E are equal:
=SUMPRODUCT((($C$11:$C$21=H55)+($F$11:$F$21=H55))*($D$11:$D$21=$E$11:$E$21)*($D$11:$D$21<>"")*($E$11:$E$21<>""))
Copy down as required.
COUNTIFS options
Based on your formula above, adding the checking for not blank cells using COUNTIFS.
=IF(C11=H55, COUNTIFS(D11, "="&E11,D11,"<>"&""),0)+IF(C19=H55, COUNTIFS(D19, "="&E19,D19,"<>"&""),0)
COUNTIFS is probably the slightly better option as it does not use array calculations. However for a small data set it wont make a noticeable difference in calculation time for most users.

Want to index/match just the unique row

I have a sheet with multiple parts belonging to different affiliates and areas. I want to write a formula that brings up the unique part from this list. I created a formula for the data set to get the row number of each unique part as shown below:
I want to just pull the rows from G which began with a 1. I try using the formula below, but it just will pull all the rows in column A:
INDEX(DATA!$A:$A,MATCH(1&"-"&$A$2&"-"&DATA!A2,DATA!G:G,0))
And produce this result:
01949765
01949765
04581664AA
04581664AA
04581914AC
04581914AC
04581914AC
04581914AD
04581915AB
Below is what I want to see:
01949765
04581664AA
04581914AC
04581914AD
04581915AB
Any formula I can use to get just the unique values?
As I understand it, the row already split the unique values, you just have to pull anything in A that has a G counterpart starting with 1.
=INDEX($A$1:$A$8,AGGREGATE(15,6,((LEFT($B$1:$B$8,1)="1")*1/(LEFT($B$1:$B$8,1)="1")*1)*ROW(INDIRECT("1:"&COUNTA($B$1:$B$8))),ROW()-10))
You'll have to adapt the different ranges to your data and the "-10" at the end depending on where you put your result.
My proposal, add a column, put in
=COUNTIF($A$2:$A2,A2)
Then filter only the value = 1. You'll see the results straightaway..
about the parts name in G..
you can load it using index()+match() function. Eg =INDEX(G:G,MATCH(A2,A:A,0)) to 'load' it.
Hope it helps.

Excel counting combinations of logical statements

I have a spreadsheet with data in multiple catagories, e.g. Pet (Dog, Cat, Rabbit), gender (M,F), mode of transport(Car,Bike,Skateboard). For each individual, these can either be true or false. I want to count the number of individuals with a particular combination of pet, gender, mode of transport. I want this to be automatic, so I can specify the gender, pet, mode of transport in cells and the formula counts based on these values.
e.g. How many people are Male, have a Dog and have a Bike? In this case, Male, Dog and Bike need to be read from cells in the spreadsheet.
I have a formula which uses indirect and offset to select columns but can't help but think there must be a better way.
Here's an example which makes it far clearer than my wordy explanation above. Thanks in advance for your help.
Is there a way of representing my data that's better suited to make this counting easier?
Google Drive Link to Excel file
A very valid - I don't download random files from the internet comment:
Here's a csv:
Name,Dog,Cat,Rabbit,Male,Female,Car,Bike,Skateboard
Alice,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE
Bob,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE
Chris,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE
Dave,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,TRUE
Ellie,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE
Frank,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE
Gerald,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE
Also the formula I used was:
=COUNTIFS( OFFSET(INDIRECT("R3C"&MATCH(L3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE,
OFFSET(INDIRECT("R3C"&MATCH(M3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE,
OFFSET(INDIRECT("R3C"&MATCH(N3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE)
Where numberOfPeople is a reference to a cell that counted the number of entries. And headings is a reference to the column headings of the table.
OFFSET and INDIRECT are volatile functions, in that they will recalculate every time excel calculates regardless if the underlying data has changed or not.
I prefer to use INDEX to return a range.
INDEX takes 3 criteria. INDEX(range,row,column). By putting 0 in the row criterion it will return the full column.
so using MATCH to find the correct column and 0 for row we get the correct column returned.
=COUNTIFS(INDEX(A:I,0,MATCH($K$2,1:1,0)),TRUE,INDEX(A:I,0,MATCH($K$3,1:1,0)),TRUE,INDEX(A:I,0,MATCH($K$4,1:1,0)),TRUE)
It is pretty easy if you use the COUNTIFS formula combined with several IF statements. Here is what should work (put in "O3" and copy down):
=COUNTIFS(IF($L3=F$2,$F$3:$F$9,$G$3:$G$9),TRUE,IF($M3=C$2,$C$3:$C$9,IF($M3=D$2,$D$3:$D$9,$E$3:$E$9)),TRUE,IF($N3=H$2,$H$3:$H$9,IF($N3=I$2,$I$3:$I$9,$J$3:$J$9)),TRUE)
This compares the given values for your categories in the inner IF statements and returns the corresponding columns to check for TRUE. What COUNTIFS does then is to count all rows where the criteria is TRUE for all given criterias. You can also expand your categories by adding more inner IF statements to return corresponding rows.
It would not be quite easy to change your data representation due to the fact that you can have multiple values for one row. You would have to split data with multiple values into multiple rows. Here is an example:
You could then just use the following formula:
=COUNTIFS($D$3:$D$14,$L3,$C$3:$C$14,$M3,$E$3:$E$14,$N3)
Having given Gender in "L3", given Pet in "M3", given Transportation in "N3".
If you have further questions, leave a comment.

Cross table comparisons, sumproduct

I am trying to compare two different Excel (2010/xlsx) tables with related data to find matches. They would be on different sheets but in the same workbook (not that it should affect the problem).
I think the best route is some combination of sumproduct, match, and index... but I haven't been able to get them to work so far. I see the main question (cell G17) being solved by creating a subset of rows from Table 2 to compare against their corresponding data in Table 1 (index/match), then using arrays to do a multiple criteria selection to count how many match the criteria I chose (sumproduct).
I have played around with vlookup, countif(s), and sumif(s) but haven't seen a good way to apply them to this problem.
You can use SUMIF as a "quasi-lookup" like this
=SUMPRODUCT((file="doc")*(modified < SUMIF(user,creator,create)))
I'm not sure how to do it in a single cell as you've asked, but I would create an extra column in the second table which uses vlookup to find the created date, and another column containing whether or not the created date is greater than the modified date. Finally, you could use countif to combine them.
To be more concrete, in your example, I would put =vlookup(F3,A$3:D$5,2,FALSE) in cell I3, and =I3>H3 into cell J3, and expand both of these down. Then cell G17 could be given by =countif(J3:J5,TRUE).

Resources