Excel - How to countif within column B excluding duplicate values from column A? - excel

The spreadsheet I am working with houses multiple duplicates for CLIENT_ID and I want to be able to count each CLIENT_ID only once, and then count the amount of a specified value within AGE_CATEGORY. Basically I want to exclude any duplicates and then countif.
| Column A | Column B |
+-----------+--------------+
| CLIENT_ID | AGE_CATEGORY |
| 1514 | 65 |
| 1517 | 65 |
| 1522 | 17 |
| 1519 | 37 |
| 1514 | 65 |
| 1516 | 28 |
| 1503 | 20 |
--- I would like for the count for people >=65 to be 2, since client# 1514 appears twice.
How can I do it?

What you need is first extract unique values from column A then count those IDs. As per my below screenshot use below formulas ExcelO365 formulas.
D2 =UNIQUE(A2:A8)
E2 =COUNTIF(A2:A8,D2#)

Create a list of unique age (category?) values — say, in Column D
— with “Data” → “Sort & Filter” → “Advanced (Filter)”. 
(Sort them if you want.) 
Enter
=SUM(--(FREQUENCY(IF(B$2:B$8=D2,A$2:A$8),A$2:A$8)>0))
into E2, press Ctrl+Shift+Enter,
and copy/drag down. 
This is the result:
| A | B | C | D | E |
---+-----------+--------------+--------------+--------------+-------+
1 | CLIENT_ID | AGE_CATEGORY | | AGE_CATEGORY | |
2 | 1514 | 65 | | 65 | 2 |
3 | 1517 | 65 | | 17 | 1 |
4 | 1522 | 17 | | 37 | 1 |
5 | 1519 | 37 | | 28 | 1 |
6 | 1514 | 65 | | 20 | 1 |
7 | 1516 | 28 | | | |
8 | 1503 | 20 | | | |
Based on this answer by SandPiper.

Assuming your data (to return values) is in A2:A8 and criteria is in B2:B8 use this ARRAY formula to check unique values >=65
=SUM(--(FREQUENCY(IF($B$2:$B$8>=65,MATCH($A$2:$A$8, $A$2:$A$8,0)),ROW($A$2:$A$8)-ROW($A$2)+1)>0))
Note for array formula you have to enter this formula with ctrl + shift + enter so that curly braces appear around the formula automatically.
Needless to say, you can change >=65 to your criteria accordingly. sample check see screenshot

Related

Excel , Multi-lookup/Match formula

I would like to use a formula in Sheet B to obtain the following transformation.
I want to vlookup stack, over, flow, super, user and the associated id's and put them into the Sheet B format. The formula would be copied horizontally across many 'Names' and then down.
Current, sheet A:
+-------------+-------+-------+
| Position_ID | Name | Value |
+-------------+-------+-------+
| 5963650267 | stack | 10 |
| 5963650267 | over | 20 |
| 5963650267 | flow | 30 |
| 5963650267 | super | 40 |
| 5963650267 | user | 50 |
| 5963650268 | stack | 90 |
| 5963650268 | over | 110 |
| 5963650268 | flow | 80 |
| 5963650268 | super | 70 |
| 5963650268 | user | 20 |
+-------------+-------+-------+
Expected, Sheet B, headers and positions ids are already pre populated:
+-------------+-------+------+------+-------+------+
| Position_ID | stack | over | flow | super | user |
+-------------+-------+------+------+-------+------+
| 5963650267 | 10 | 20 | 30 | 40 | 50 |
| 5963650268 | 90 | 110 | 80 | 70 | 20 |
+-------------+-------+------+------+-------+------+
Assuming the data in Sheet A is located at A1:C11 (adjust as required), enter this Formula Array in Sheet B at B2 then copy to all required cells (i.e. C2:F2 and B3:F3)
=INDEX('Sheet A'!$C$1:$C$11,
MATCH(CONCATENATE($A2,"|",B$1),
CONCATENATE('Sheet A'!$A$1:$A$11,"|",'Sheet A'!$B$1:$B$11),0))
Formula Array must be entered by holding down CTRL + SHIFT + ENTER
Apologies for the formatting - but if you add the vlookups to the empty shell of position_ids by name on sheet b it should give you the grid you're looking for.
Sheeta! ID&Name Position_ID Name Value
=C2&D2 1 stack 10
=C3&D3 1 over 20
=C4&D4 1 flow 30
=C5&D5 1 super 40
=C6&D6 1 user 50
=C7&D7 2 stack 90
=C8&D8 2 over 110
=C9&D9 2 flow 80
=C10&D10 2 super 70
=C11&D11 2 user 20
Sheetb! stack over flow super user
1 =VLOOKUP($A14&B$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&C$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&D$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&E$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&F$13,$B$2:$E$11,4,FALSE)
2 =VLOOKUP($A15&B$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&C$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&D$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&E$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&F$13,$B$2:$E$11,4,FALSE)
Sheetb! stack over flow super user
1 10 20 30 40 50
2 90 110 80 70 20

MATCH function with #N/D cells

I have the following table in Excel:
+----+--------+-------------+------------+-------------+
| | A | B | C | D |
+----+--------+-------------+------------+-------------+
| 1 | Month | Price alpha | Price Beta | Price Gamma |
| 2 | 201601 | | #DIV/0! | |
| 3 | 201602 | 51 | 21 | 93 |
| 4 | 201603 | 47 | 22 | 97 |
| 5 | 201604 | 44 | 28 | 92 |
| 6 | 201605 | 58 | 44 | 98 |
| 7 | 201606 | #N/D | 28 | 35 |
| 8 | 201607 | #N/D | 44 | #N/D |
| 9 | 201608 | #N/D | #N/D | #N/D |
| 10 | 201609 | #N/D | #N/D | #N/D |
| 11 | 201610 | #N/D | #N/D | #N/D |
| 12 | 201611 | #N/D | #N/D | #N/D |
| 13 | 201612 | #N/D | #N/D | #N/D |
+----+--------+-------------+------------+-------------+
For each column there is a variable list of numerc values (and, maybe, few #DIV/0! errors) and, from a specific rows to the end of the table, only #N/D values.
My goal is to have, for each column, then first Month where the #N/D values start.
The results would be:
Price alpha: 201606
Price Beta: 201608
Price gamma: 201607
For this king of tasks I usually write a function cobining MATCH and INDEX but, unfortunally, the MATCH function doesn't accept #N/D as value to look for in the matrix.
How could I get the first #N/D error for each column?
You have to use an array function (Ctrl+Shift+Enter).
{=MATCH(TRUE,ISNA(A:A),0)}
Are you not putting the #N/D text within quotation marks when using the MATCH function coupled with the INDEX function: =INDEX(Month,MATCH("#N/D",Price alpha,0),1)? I assume that you have the columns named by the headers.

How to get and concatenate values from one column based on another column in Excel

Excel is beating me up for a day here.
I have this table:
+---+--------+--------+--------+--------+
| | A | B | C | D |
+---+--------+--------+--------+--------+
| 1 | AGE | EX# | DG1 | DG2 |
+---+--------+--------+--------+--------+
| 2 | 19 | C01 | ASC | |
+---+--------+--------+--------+--------+
| 3 | 45 | C02 | ATR | |
+---+--------+--------+--------+--------+
| 4 | 27 | C03 | LSI | |
+---+--------+--------+--------+--------+
| 5 | 15 | C04 | LSI | |
+---+--------+--------+--------+--------+
| 6 | 49 | C05 | ASC | AGC |
+---+--------+--------+--------+--------+
| 7 | 76 | C06 | AGC | |
+---+--------+--------+--------+--------+
| 8 | 33 | C07 | ASC | |
+---+--------+--------+--------+--------+
| 9 | 17 | C08 | LSI | |
+---+--------+--------+--------+--------+
Now, I need to create a new table based on that data, with one row and one column, which I'll fill column A and need a formula to fill column B:
+----+--------+---------------+
| | A | B |
+--=-+--------+---------------+
| | DG | AGE |
+--=-+--------+---------------+
| 10 | AGC | 49, 76 |
+----+--------+---------------+
| 11 | ASC | 19, 33, 49 |
+----+--------+---------------+
| 12 | ATR | 45 |
+----+--------+---------------+
| 13 | LSI | 15, 17, 27 |
+----+--------+---------------+
So I need a formula to check the first table's columns C and D for each DGs, and check the age of each one in column A, and then concatenate all values that match into one cell with a , as a separator.
Can anyone help me?
Thanks
On the great excel website from Chip Pierson, I found the custom function: StringConcat. Just copy-paste the code in a VBA module.
Something like the following formula (in cell B10 & fill down)should work for you. It's an array formula (commit with [ctrl-shift-enter]
=StringConcat(", ",IF(Sheet1!$B$2:$C$100=A10,Sheet1!$A$2:$A$100,""))
You'll have to adjust the ranges off course.

Excel: sort column with mixed numbers and letters?

I am working of the dataset in Excel that I obtained from an experiment. Since I needed some ratings (and I wanted the raters to be blind) I completely randomized the answers and now I can't put them back in order!
This is what I have:
1A
38R
22R
7A
41R
64A
etc...
And this is what I need in the end:
1A
2A
3A
...
99R
100R
101R
Thank you!
I have created two new columns (B and C in this case, as in the other example posted).
I have typed LEFT(A1,LEN(A1)-1) in column B to get the number; then =RIGHT(A1,1) in column C to get the letter; finally I can sort by B and C.
You will not get your desired output by sorting alphabetically, because 100R would come before 2A.
If your values will always be in the format of a number followed by a single character and will be at most 5 characters long, you can use #Scott Craner's formula =RIGHT("00000"&A1,5) to pad the left of your value with "0" so that you can alphabetize correctly. 100R will become 0100R. 2A will become 0002A. These will now alphabetize correctly.
Now you can simply sort your range by column B ascending alphabetically.
If you need more characters, just add as many zeroes as characters to the formula, and change the 5 in the formula to your new number of characters.
Here is an example excel file.
INPUT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 38R | 0038R |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 7A | 0007A |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+
RESULT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 7A | 0007A |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 38R | 0038R |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+

Count text occurrences in a column in Excel

I have the following list in Excel:
+-------+----------+
| am | ipiresia |
+-------+----------+
| 50470 | 29 |
| 50470 | 43 |
| 50433 | 29 |
| 6417 | 51 |
| 6417 | 52 |
| 6417 | 53 |
| 4960 | 25 |
| 4960 | 26 |
| 5567 | 89 |
| 6716 | 88 |
+-------+----------+
I want to add a column, let's say 'num' and count the occurrences of column 'am' in a row adding one when a new occurrence happens as follows:
+-------+----------+-----+
| am | ipiresia | num |
+-------+----------+-----+
| 50470 | 29 | 1 |
| 50470 | 43 | 2 |
| 50433 | 29 | 1 |
| 6417 | 51 | 1 |
| 6417 | 52 | 2 |
| 6417 | 53 | 3 |
| 4960 | 25 | 1 |
| 4960 | 26 | 2 |
| 5567 | 89 | 1 |
| 6716 | 88 | 1 |
+-------+----------+-----+
Is it possible to get this automatically with a formula in Excel?
yes,
my example:
(assume you start your table containing 3 columns at Excels origin at A1 without header lines)
Then fill C1 with value "1"
and then start in C2 with entering a formula
simple like this:
=if($A2=$A1;$C1+1;1)
then you drag C2 down at the cells downright located autofill position as far as you want. Most times also double click works to let Excel autofill the columns down to the end of you prefilled table.
If you need assistance for AutoFill press F1 in Excel an the help with tell you in detail.
Assuming the sample table starts at A1 (with headers) the following formula will provide the expected results even if the list is not sorted.
=COUNTIF($A$1:$A2,A2)
Enter the formula at cell C2 then paste it down to the last cell of the data (or use AutoFill)

Resources