My searches for answers have been limited by my lack of knowledge of the appropriate terminology. My goal is to count the number of times a specific username appears in one column AND the number 1 appears in another column for that user. I attempted to use COUNTIF, but it doesn't seem to format for that purpose.
What I'm needing is to count the number of instances "username" appears in column K when "1" appears in column Q.
If you have =COUNTIFS (you don't mention which version of Excel) please try, in Row1 and copied down to suit:
=COUNTIFS(Q:Q,1,K:K,K1)
there may be better ways (eg a PivotTable, an array formula or =SUMPRODUCT) but this could be one of the simplest.
Alternatively of course just filter and read the count in the bottom left-hand corner of your screen.
Showing COUNTIFS, SUMPRODUCT, PivotTable and filter options:
In this special case, because one of your criteria is 1, you might also use SUMIFS.
Because the data happens to start with a list of unique Users in order the COUNTIFS version in Row2 (adjusted to K2 from K1) entered with Ctrl+Shift+Enter and copied down to Row 6 will show a result similar to that in the PT.
Related
I'm trying to create a formula for a countback feature in google sheets if possible.
I have a list of competitors race times (W4:W93) and have them ranked (X4:X93) and but if I get Identical times it throws out another formula for overall results.
my sticking point is I can't work out how to compare if the value in any cell is equal to another cell in the same column excluding itself, I have found plenty of info on equal values but not if they are in the same column.
any help would be much appreciated.
I note that this question has been voted down with no explanatory comments. The question is not on hold, it is not closed because it might be duplicate, or answered elsewhere, and no one has edited the question to provide greater clarity. That seems a pretty rough call to me.
In any event, I'm pretty sure that I've been in the situation described by the OP many times and I've had to be creative about finding and removing duplicate values. There are several ways to find/highlight/manipulate duplicate values, though Google doesn't seem to have as many options as Excel. One method is to use conditional formatting and this YouTube video explains it very well.
But I will use one of my all-time absolute favourite formulae to find duplicates. In addition, since the OP is working with 90 competitors, finding the duplicates is only the task, the OP also needs to arrange them in a way that assists analysis.
This Google spreadsheet shows the workings:
First, create a header, say, "Equal Rank" for column Y (the first column after "Ranking") and insert this formula in cell Y4:
=if(countif($W:$W,W4)=1,"Unique","Duplicate")
The formula has two components.
COUNTIF
IF statement
The COUNTIF looks at cell W4 (the race time) in the first row of results. The count range is Column W; the range could just as easily be limited to actual data but the key is that it is expressed as an "absolute" (note the $ signs in the range).The formula counts how many times the value in cell W4 appears in the range.
The IF statement evaluates the result of the COUNTIF. If the result appears only once, then the cell value is "Unique". If the value appears more than once, then it is a "Duplicate" value.
The OP has 90 competitors and will need to drill down to the duplicate results quickly. So, I suggest a variation of the classic formula, this:
=if(countif($W$4:$W$93,W4)=1,"",X4)
The formula still consists of two components, but if the result is unique, then no value is entered; conversely if the result is a duplicate, then the existing "Rank" (cell X4) is returned. BTW, this version shows how the range address would look if you evaluated only the populated range.
Now, sort the range A3:Y93 (I am assuming there is relevant data in columns A-V). FWIW, I inserted a column "Sequence" and gave it a numeric sequence so that once the "Equal Ranks" had been fixed, I could resort on the "Sequence" column to return the data to the original sort order - the OP may or may not need this.
To aggregate the duplicate values:
Select the Range> right-click > Sort range > "Data has Header Row" = checked> 'Sort by' "Equal Rank", Sort order: "A->Z".
From here, Race Times could be adjusted by a tenth, or hundredth, of a second to avoid duplicate times.
Once this is complete, select the full range again, and resort. In my case I used my "Sequence" column to return the data to the original sort order.
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....
I am an excel beginner and I would like to do the following.
Let row1= (a_1 a_2 a_3) and row2= (b_1 b_2 b_3).
I want excel to calculate the largest number among the products (a_1b_1, a_2b_2, a_3b_3).
It is very difficult to look up these things for I am not sure what kind of calculation I am doing and it is hard to explain.
Take a third column, C and enter formula in C1 as $A1*$B1. Pull it down vertically to all other rows so that row number gets incremented for each.
Then in the fourth column, use the formula MAX(C:C)
The following formula, array-entered, gives you the result of the largest number among the products:
{=MATCH(A1:C1*A2:C2)}
(provided your data is in A1:C2 in the form you presented it).
For explanations on how to insert array formula in excel see e.g. this microsoft link; in short, you type the formula without the curly brackets and confirm with CTRL+SHIFT+ENTER instead of only ENTER.
If you want to find where this couple of numbers is (in your case: which column), I would try this:
{=MATCH(MAX(A1:C1*A2:C2);A1:C1*A2:C2;0)}
(also array-entered).
you can do that, or make a pivot with the raw data and get the MAX/MIN/AVG, based on the pivot options. I tend to use that instead and then vlookup the ID to the pivot to get whatever aggregate you need.
I have two columns with team names and two columns with corresponding stats. I need to go through the 2 columns and find the stats that match the team name, and they need to be in order. VLOOKUP, MATCH, and SEARCH don't seem to work with multiple columns. Does anyone know how this can be done?
Assuming in your picture, the "Home" title is in cell B2 then the following array formula can be put in the cells H3:L7 (array formulas need to be entered with Ctrl+Shift+Enter)
=IFERROR(OFFSET($D$1,-1+SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)),--NOT((INDEX($B:$B,SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)))=H$2))),"")
Let me break it down...
the logic is: OFFSET(top_of_results,row_number_that_has_Nth_team_score,0_or_1_for_home_or_away)
this is wrapped in an IFERROR in for where there isn't e.g. a 5th score for team A
using the array part IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X" we get an array of that has the ROW number if either (done using +) B or C have a value matching our team header (H$2) or an X otherwise
using SMALL(...,ROW()-ROW($2:$2)) we get the Nth smallest row, based on 1st being in row 3, 2nd in row 4 etc.
to get whether it is home or away, we check column B on our row to see if it matches --NOT((INDEX($B:$B,row_number_that_has_Nth_team_score-O)=H$2)) this gives 0 for home, 1 for away and this is used to offset the column
Hopefully it makes sense. Array formulas are very powerful, if a little confusing :-) I recommend CPearson's intro for more information.
Good luck!
I have two excel sheets where I need to match three values to return a fourth. The similar columns are month, agent, and subdomain. The fourth column is called difference.
Concatenate would work, as per #MakeCents suggestion, but if you don't want a helper column, SUMPRODUCT would work.
example:
=SUMPRODUCT(--(A2:A12="d"),--(B2:B12="S"),--(C2:C12="Apr"),D2:D12)
would search range A2:A12 for "d", B2:B12 for "S" and C2:C12 for "Apr", and return the value fom D2:D12 that corresponds to where all 3 are true. If multiple lines match, it will add the value in D2:D12 for all matching rows.
The -- is used to change the True/False results into 0 and 1 for use in multiplication
Limitations of SUMPRODUCT
Recommended to specify the range explicitly; it will be slower with just
column references
(A1:A4000 is ok, A:A is not)
It will return an error if any of the values are errors
It will return numeric results only - text is evaluated as Zero
Although I believe #MakeCents comment / suggestion on how to do this is the way I would go since it is the simplest, you could accomplish this a different way (MUCH more processor-intensive, though) using the Index() and Match() functions and Array formulas.
For example, suppose your 3 columns of data you're looking to match against are columns A-C and you're looking to return the matching value from column D in Sheet1
Now, the 3 values you're looking to have matched are in cells A1, B1 & C1 of Sheet2, you could use the following formula:
=INDEX(Sheet1!D:D,MATCH(1,(Sheet1!A:A=A1)*(Sheet1!B:B=B1)*(Sheet1!C:C=C1),0))
And ENTER IT AS AN ARRAY FORMULA by pressing Ctrl + Shift + Enter
Hope this helps!
You are looking for a Lookup with multiple criteria.
One of the most robust options is
=INDEX(D:D,SUMPRODUCT(--(A:A="d"),--(B:B="S"),--(C:C="Apr"),ROW(D:D)),0)
It does not need to be entered as an array formula.
Taken from [1] (blogs.office.com).
See also this very complete answer, which summarizes this and other options for performing a lookup with multiple criteria.
PS1: Note that I used references to full columns, as per this.
PS2: This can be considered an enhancement to the solution by Sean for the case when the output column does not contain numbers.
References
[1] This post is written by JP Pinto, the winner of the Great White Shark Award given for the best article written about VLOOKUP during VLOOKUP Week.
Try this
=IF(A4=Data!$A$4:$A$741,IF(B4=Data!$B$4:$B$741,"Hai"))