Excel - VLOOKUP or COUNTIF to count Matches from 2 Columns? - excel

I'm trying to get a count of matches from two columns. Let's say I have a table with the following data.
Cars
In column A I have colours of cars e.g. Red, Yellow, Black, Green
In column B I have the type of car e.g. Diesel, Automatic, Manual
I want a count of all red cards that run on diesel so which function would I use?
Column A has 3 red cars
Column B has 6 diesel cars in total but only 1 of the red cars is a diesel.
I've tried :
=COUNTIF(A2:A10,"Red")+COUNTIF(B2:B10,"Diesel")
But it gives a combined count of all red cars and all diesel cars (9), not all red diesel cars, which should be 1.

You could use the =COUNTIFS() formula:
=COUNTIFS(A1:A10,"Red",B1:B10,"Diesel")

You choud do an operation for each row, and sum all.

Related

Excel Formula to return all rows and columns corresponding to search string

I'm trying to lookup two sheets in Spreadsheet.
One has the search value and other has all the data corresponding to the search string.
I'm trying to find a formula that will search the value and return all the corresponding rows. Another thing is that it has to return the entire row and columns correspoing to that string and not only one.
I'm using this Vlookup formula as of now but any help will do:=
ArrayFormula(VLOOKUP(A1,Sheet2!A2:AE196,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},FALSE))
A2:is the seach string, and used array to define the Columns to be returned.
But the formula returns only one row corresponding to the string and not all the rows.
Is there a formula that returns all rows and entire values in those rows correspoinding to the search string?
EX :Sheet1:search criteria
Search
Apple
Mango
melon
Ex:Sheet 2: Data
Name
Colour
no
Apple
red
5
Banana
yellow
3
Apple
red
25
Mango
yellow
1
Mango
yellow
10
Expected result for Apple(A1 in the formula) as search string:
Name
Colour
no
Apple
red
5
Apple
red
25
Actual result:
Name
Colour
no
Apple
red
5
You should use FILTER or QUERY
=FILTER(Sheet2!A2:AE196,Sheet2!A2:A196=A1)
=QUERY(Sheet2!A2:AE196,"select * where A='"&A1&"'",1)

Excel: How to add a column from other sheet based on a key column?

I have 2 list. Both have a lot of column. I would like to insert a column from Sheet2 to Sheet1 based on a ceratin key column. Also sheet2 have much more rows than sheet1 so it ll be inserted only partly and still there ll be elements with no matches. For an example:
Sheet1:
Names ID Car Color
John 1 Audi Empty
Andy 4 Toyota Empty
Mike 3 BMW Empty
Tony 2 Suzuki Empty
Sheet2:
ID Cost Color
6 200 Blue
3 200 Red
4 300 Green
5 100 Red
1 50 Black
I would like to get the "color" from Sheet2 to Sheet1 by using the "ID". Using Excel 2010. I suspect I need INDEX+MATCH combination, but the examples I can find are not detailed and more simple so I coudn't figure out how to use them.
How about inserting this formula on Column D in the first row, then dropping the formula down:
=VLOOKUP(B1,Sheet2!$1:$1048576,3,FALSE)
Or to find the column that contains "Color", use Index Match Match, as follows:
=INDEX(Sheet2!$1:$1048576,MATCH(Sheet1!B2,Sheet2!A:A,0),MATCH("Color",Sheet2!$1:$1,0))
This will find the value in Column B in Sheet2 and give you the row number, then it will find the Column that contains "Color" and return the Column number, with those two numbers Index will return your color.

How to Summarise Positive / Negative Number without Adding New Column in Excel Pivot Table

Raw data is following format:
Name Team Talent
---------------------------
Quill Red 500
Drax Red -900
Ego Blue 2,000
Kraglin Red -200
Rocket Red 900
How can we make a pivot table like below without adding new column to original data:
Team Sum_Pos_Talent Sum_Neg_Talent
-----------------------------------------
Red 1,400 -1,100
Blue 2,000 0
Tried adding calculated fields, but the calculation is on the number on pivot table, not on each row of data.
You can use SUMIFS.
Sum_Pos_Talent
=SUMIFS($C$2:$C$6,$B$2:$B$6,E2,$C$2:$C$6,">0")
Where C2:C6 is the Talent column, B2:B6 is the Team Column, E2 is the name of the team in the other table.
Similarly Sum_Neg_Talent
=SUMIFS($C$2:$C$6,$B$2:$B$6,E2,$C$2:$C$6,"<0")
Sort the data to separate positives from negatives and insert a new row of headers between the two sets (say rename Talent to Sum_Pos_Talent and for inserted header switch to Sum_Neg_Talent). Then, assuming Team is in B1 (and in B5) create the PT from multiple consolidation ranges (B1:C4 and B5:C7) eg as here.

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

Formula to count Text and dates by multiple criteria

I have been trying to create a formula that will count the number of occurrences based on multiple criteria. In the display below I am looking to populate cell C5 with the number of rows that meet a given criteria. In this case, when the start date is between C1 and C2 and the team is Green or Blue or the Department is WAZ. I have been able to get counts to work based on just the date or just the team but have been unable to find a solution with all 3.
Countifs is what I have been trying but without success. I can only get a portion of the criteria to work. As soon as I add in the date part it errors out.
Start 12/21/14 12/28/14 1/4/15
end 12/27/14 1/3/15 1/10/15
Project ID start date end date team Department
1 1/7/15 6/26/15 Blue SRT
2 12/27/14 1/23/18 Green DFT
3 1/8/15 3/20/15 Red DFT
4 1/3/15 6/20/15 Red WAZ
5 12/29/14 7/12/15 Blue DFT
Supposing that you have the following criteria:
J5 = red
J6 = DFT
and your are looking for dates (start & end) in C1 and C2.
I am using my example, please follow the data in the image below:
so put this formula in cell C3, which shows the number of rows for your query:
=COUNTIFS($C$5:$C$11,">="&C1,$D$5:$D$11,"<="&C2,E5:E11,J5,F5:F11,J6)
as you see the formula yields 2 because there are only two rows that match these conditions. (the rows are in bold, rows 6 and 7).
So basically a countifs can contain several criteria:
COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2, criteria_range3, criteria3 ...)

Resources