Need a Formula to Countif a Range based on an input - excel

Above is a snippet of data that I have (in Sheet1).
My task is to count the number of times "C" is in, let's say from B to C, (the formula will be written in Sheet2 for this). I have the code for that and it works fine.
But what can I do to get the count based on a particular UserID entered in cell A1 of Sheet2.
For ex: if 'Sheet2'!A1=3 then the count in row 3 of form B to C should be given:
(Result = Countif('Sheet1'!"B2:B4","C"))
Hope my explanation was understandable. I need a formula for this not macro.
I tried to get the row ID using Index Match but I am not able to combine it with CountIf.
Both VLOOKUP and INDEX MATCH can be used only if I want one cell value, but not multiple values in same row.
Result = Countif('Sheet1'!"B2:B4","C")

Not the most elegant formula, but the following should achieve your desired result:
=COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!B:B,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!C:C,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!D:D,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!E:E,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!F:F,"C")

If you know how to use Names in excel, you can define the following names:
Rng_Data represents all your data in Column B to F
List_User represents all your data in Column A
then use the following formula to find the desired count:
=SUMPRODUCT((Rng_Data="C")*(List_User=Sheet2!A1))
Where Sheet2!A1 is the given User ID in cell A1 on your second sheet. You can drag this formula down to apply to the rest.
In my following screen-shot, I used two sets of data to test the outcome. The first set is the same as yours and the User ID in Column A is unique. In the second set of data, there are duplicated User ID and the formula still finds the occurrence of C for the given User ID as highlighted.
SUMPRODUCT sometimes work like COUNTIFS but in a more powerful way.
You can read this article to learn more about SUMPRODUCT: Excel SUMPRODUCT function with formula examples
Cheers :)

Related

Need assistance me with this Excel Task? Unable to generate the proper results

Looking for help with this task. Here's is a portion of the table I'm working with:
What I'm trying to do is have the cells in Column B (MWD) return the value of the adjacent cells in Column C (Pseudo). Column A (Data Set) has the same values as Colum B but including duplicates. I need a formula where the duplicates in Column A will return the same value that it matches in column B.
Example: I need...
all the duplicate 1010001's to return pseudo 1
all the duplicate 1020001's to return pseudo 2
all the duplicate 1020002's to return pseudo 3
and so on...
I was trying to use index match function but don't know if I'm constructing the formula wrong or if it's the correct formula to use.
If data is sorted by column A, you can use one formula:
=IF(COUNTIF($A$1:A2,A2)>1,C1,C1+1)
if not, then other
=IF(COUNTIF($A$1:A2,A2)>1,INDEX($C$1:C2,MATCH(A2,$A$1:A2,0)),MAX($C$1:C1)+1)
in both cases copy the formula in second row (in C2 cell in my examples). To the first row add 1 manually.
First example:
Second example:

Trying to get 2 field to match data in a second sheet and return a value

Im trying to get the following working in excel and i just cant seem to do it.
I have 2 sheets, one with data in (Sheet 2), one where ive created a questions box with a response field (Sheet 1).
So in the data sheet there are columns A, B and C.
On the questions box (Sheet 1) i need to know if a figure put into A and a figure put into B, both match the data in columns A and B in Sheet 2 if they do i want to return the figure which corresponds in column C in sheet 3 to column C in sheet 1.
Ive assumed i need to use an IF AND formula and have tried the following in various different ways, but all it gives me back each time is 0.
=IF(AND(A1=Sheet3!A:A,B1=Sheet3!B:B),Sheet3!C:C,0)
Im at the end of my tether with this so any help would be appreciated.
This is an array formula, apply this by hitting Ctrl+Shift+Enter while still in the formula bar.
=IFERROR(INDEX(Sheet3!C:C,SMALL(IF(A1=Sheet3!A:A,IF(B1=Sheet3!B:B,ROW(Sheet3!A:A)),1)),"No Match Found")
This should work by building an array of the row numbers that have a match for both A and B then take the first match, SMALL([array],1), by taking the first smallest number from the array and feeding that to INDEX().
This formula can be adjusted to be dragged so that it returns multiple matches by changing small to SMALL([array],ROW(1:1) and dragging the formula down, though I would suggest changing "No Match Found" to "" so that you just have blank cells once you have displayed all of the matches.
If you're happy using an array formula (press Ctrl and Shift when you press Enter), then this formula should work fine:
I originally read it as you wanted to get the info from Sheet 3, so this would have worked:
=INDEX(Sheet3!B1:B6,MATCH(INDEX(Sheet2!C1:C6,MATCH(A1&B1,Sheet2!A1:A6&Sheet2!B1:B6,0),1),Sheet3!A1:A6,0),1)
But re-reading, I don't think that's the case, so this should do...
=INDEX(Sheet2!C1:C6,MATCH(A1&B1,Sheet2!A1:A6&Sheet2!B1:B6,0),1)
This is using:
A1 as your first answer to compare values in A1:A6 in Sheet2
B1 as your first answer to compare values in B1:B6 in Sheet2
Gets the corresponding value where both the above two match from C1:C6 in Sheet2.
Then, it looks for that value in A1:A6 in Sheet3 and returns the corresponding value from B1:B6 in Sheet3

Sum column of values where separate column contains duplicate

I need to sum all values in Column A where Column B is a duplicate.
Above is a sample of the data. Column B has urls and Column A has counts for the urls. What I want is to sum the values in Column A for duplicate values in Column B.
Example:
The output for _.apelabs.net should be 6.
How can I achieve this?
I think you are looking for the function =COUNTIF(Range,Criteria)
Here is a link that shows a usage example.
As #Andresson stated, if you're trying to count the number of times a specific url appears, you might want to use the COUNTIF function: =COUNTIF(range, criteria).
COUNTIF Example:
Using =COUNTIF(B:B, "_.apelabs.net")
would return 3 in your sample data (assuming your image includes the only instances of "_.apelabs.net").
This example of the COUNTIF function is the same as saying, "count the total number of times a cell in Column B (i.e. B:B) equals "_.apelabs.net"."
However, if you're wanting to sum together all the values in Column A where the corresponding url in Column B matches the given criteria, you'll want the SUMIF function: =SUMIF(range, criteria, [sum_range]).
SUMIF Example:
Using =SUMIF(B:B, "_.apelabs.net", A:A)
would return 5 in your sample data (again assuming your image includes the only instances of "_.apelabs.net").
This example of the SUMIF function is the same as saying, "each time a cell in Column B (i.e. B:B) equals "_.apelabs.net", sum together the values in Column A (i.e. A:A) that are located in the same row as each "_.apelabs.net" found in Column B."
Additionally, you can also use a pivot table, as #ScottCraner suggested. It's all a matter in how you want to present your findings.

IF Function/VLOOKUP Combo

So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.

How to look up value in a column, and assign specific entries

I have a sheet in Excel where the columns contain different names of people that are in different teams in my department (i.e. Names in Column 1 are in Team 1).
For another sheet, I need to have a formula that achieves the following:If I write a name in Cell B2 that can be found in the first column of that other sheet (Team 1), Excel should populate cell B6 with "Team 1".
If instead, the name I wrote is found in the second column, then the text should read "Team 2".
I've tried a couple of different formulas w/o success, and stringing a lot of IF and OR functions together is way too cumbersome. Anybody has a better solution?
If you need this formula for more then only two column then id use the formula
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6)))
Say you have a set-up like:
And in B1 of Sheet2 you enter Name3, you want it to return TEAM1 as shown below:
The only catch to this formula is that you will need to tell it how many columns are before your data so if you have a table more like:
Then you need to tell the formula that there are 2 rows before your data starts, your new formula will be
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6))-2)
Notice the -2 before the last parenthesis this is to indicate that there are 2 columns BEFORE you data.
and the new result for looking up say NAME20 would become as follows:
*EXPLANATION: *
The formula works as follows , I will do it all on one page for easier viewing and instead of Sheet2!B2 and B6 I will use G2, and G6 on the same sheet as the data.
First we look at all values in the Range A1:E6 and find the one with the matching name so we use
=A1:E6=G2
Now when you enter this into the cell you will recieve a #VALUE,but if you goto the Formula Bar and press F9 it will shwo you the full value of the formula
{FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE}
In this we know that one cell contains the Name we searched for, this is represented by the TRUE
Now when using a formula like SUMPRODUCT, FALSE = 0 and TRUE = 1
So to get the column we mutiply every result by the column they are in.
=SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6))
So any cells that don't =G2 are FAlSE or 0, and when you multiply the column of that cell by 0 (because false = 0) it will simply result in 0. But for the one cell that IS TRUE or 1 When you multiply the column of that cell by 1 (because TRUE = 1) The product will be the cells column number
So as shown in the picture when looking for NAME13 the result of the sumproduct is 3 (its column)
Then to return the TEAM for that name, we use the INDEX function will return the value in a cell at the given cordinates.
In this case we want the value from A1:E1 that is in the same column as the Name we matched. When looked at as an Array A1:E1 looks like
{"TEAM1","TEAM2","TEAM3","TEAM4","TEAM5"}
And we want to return the value in that array at the same position as the column number of our cell, Minus any nonincluded column before the data, thus the reason for the -2 in the secon example I gave you.
So:
=INDEX(A1:E1,SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6)))
In this example excel interprets this formula as
Return the 3rd value (the 3 comes from the sumproduct as explained earlier) in the list of value from A1:E1. And that value would be TEAM3.
use a MATCH() or VLOOKUP() function inside an IF(). SOmthing like:
IF(NOT(ISERROR(MATCH(...)));"Team1";"")
Did you know you can browse functions by catergoty (such as Search), just clikc the fx left of your formula bar and use the drop down box. Each formula comes with a description with usually rather clear information...

Resources