Count text occurrences in a column in Excel - 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)

Related

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

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

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.

excel formula series fill in custom order

i have two table of excel
1st/
1 | blawa1 |blawb1 |blawc1 |blawd1 |
2 | blawa2 |blawb2 |blawc2 |blawd2 |
3 | blawa3 |blawb3 |blawc3 |blawd3 |
...
2nd/ that should be linked to 1st table in the folowing form
1 | blawa1 |
2 | blawb1 |
3 | blawc1 |
4 | blawd1 |
5 | |
6 | blawa2 |
7 | blawb2 |
8 | blawc2 |
9 | blawd2 |
10 | |
11 | blawa3 |
12 | blawb3 |
13 | blawc3 |
14 | blawd3 |
15 | |
16 | blawa4 |
17 | blawb4 |
18 | blawc4 |
19 | blawd4 |
20 | |
...
when i write the formula in table 2 and drag it down, the formula did not fill in series that i want.
e.g: it jump from "blawa1" to "blawa6" , while it should be "blawa2"
With data in columns A through D, pick some cell, say F4, and enter:
=OFFSET($A$1,ROUNDUP(ROWS($1:1)/5,0)-1,MOD(ROWS($1:1)-1,5))
and copy down:
Using similar formulas, any two dimensional table can be mapped into a single column or a single row.
If you see zeros in the output single column rather than the spaces, fill column E with blanks.
You can use the below formula
=IF(INDIRECT(CHAR(64+MOD(ROW()+4,5)+1) & (INT((ROW()-1)/5)+1))=0,"",INDIRECT(CHAR(64+MOD(ROW()+4,5)+1) & (INT((ROW()-1)/5)+1)))
copy the this cell to required number of times.

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 one column into many column

I would like to do the following data sorting/reshaping in excel. Is there a way to do this?
From this
+--------+-------+
| Sample | Value |
+--------+-------+
| 1 | 30 |
| 1 | 10 |
| 2 | 6 |
| 2 | 5 |
| 3 | 62 |
| 3 | 20 |
+--------+-------+
To this
+---------+---------+---------+
| Sample1 | Sample2 | Sample3 |
+---------+---------+---------+
| 30 | 6 | 62 |
| 10 | 5 | 20 |
+---------+---------+---------+
edit: please excuse my ugly table.
If 30 is in B2, please try in C2:
=OFFSET($B2,2*(COLUMN()-3),0)
copied across and down to suit.

Resources