Formula to count each individual digit in a cell per column in Excel - excel

I have a list of numbers like below. And I need to know how many of each number are in each cell per column.
My List
1
2
3
4
10
11
12
13
14
21
22
23
24
I need to know how many times 1 occurs throughout the whole list, including double digit numbers, and I need to do this for each number 0-9. The reason I don't just count them is because I have a total of 1,400 numbers that I need to break down. I have tried =COUNTIF but unfortunately it sees numbers such as 22 and ONE number, when I need it to tell me that there are 2, 2s. Is there a way? Thanks!

With your data in A2:A15 and the digit to count in B2 you can use following array formula (confirmed with Ctrl+Shift+Enter):
=SUM(LEN(A2:A15)-LEN(SUBSTITUTE(A2:A15,B2,"")))

This would be a way of doing it:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,"1","")))
and the same for "2", "3" etc. or put digits 0-9 in a range of cells starting at (say) B1 and enter this in C1 and pull down:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,B1,"")))
Is an array formula and must be entered with CtrlShiftEnter

To count 1's, use something like:
=SUMPRODUCT(LEN(A2:A14)-LEN(SUBSTITUTE(A2:A14,"1","")))
You can count any digit or character or substring this way.

If you're only ever considering up to double-digit numbers, as you appear to suggest:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)="1"))
Or, more dynamically, with e.g. 1 in B1:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)=""&B1))
and copied down.
Regards

Related

How to add 5 cells consecutively after an interval of 5 cells in a row of 200 cells?

I have a row of 200 cells. I have to add/average first five cells (A:E), and then take a break of 5 cells and then add/average second five cells (K:O) and so on till the end of the row. How can I do this?
I have tried doing it manually. Actually, I can do this manually but wanted to know if I can do this automatically.
I did a test making some faking data like this:
It's just a bunch of numbers from A1 to CB1. 80 numbers in total. 5 first numbers are 1, then next 5 are 2, next 5 numbers are again 1, then next 5 numbers are again 2, and so on.
This mean that there are 80 numbers, where 40 are 1 and 40 are 2. I want to get the average of first five cells (A:E), and then take a break of 5 cells and then average second five cells (K:O) and so on till the end of the row. In other words, I want to get the average of the 40 cells that contains a 1 value, and it should return a 1.
For this, I've used an array formula:
=AVERAGE(IF(VALUE(RIGHT(COLUMN(A1:CB1);1))<6;IF(VALUE(RIGHT(COLUMN(A1:CB1);1))>0;A1:CB1)))
NOTE: Because this is an array formula, it must be inserted pressing ENTER+CTRL+SHIFT instead of
only ENTER, or it won't work!
How this works?
You want to sum/average only values that are in columns where last digit of column number is 1 to 5, this means columns 1,2,3,4,5,11,12,13,14,15,21,22,23,24,25, and so on. So this works this way:
The part that says COLUMN(A1:CB1) will get an array of column numbers.
RIGHT(COLUMN(A1:CB1);1) will get last digit of each column number, but as text
VALUE(RIGHT(COLUMN(A1:CB1);1)) will convert that last digit into a number.
Then with both IFS, we get an array of only those values where last digit of column number is >0 and <6, and we get the average. I get as result of my average 1 and it's true, because the average of 40 times 1 is equal to 1.
Hope this works for you. You can adapt this easily to make it work with 200 cells.
For example:
In A2 put:
=IF(MOD(COLUMN(),10)=1,AVERAGE(INDEX(1:1,,COLUMN()):INDEX(1:1,,COLUMN()+4)),"")
Drag right.
You can use SUMPRODUCT to add the amounts in the columns and divide by 100:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/100
if you do not always have 200 numbers you can make the 100 more dynamic with another SUMPRODUCT:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/SUMPRODUCT(ISEVEN(INT((COLUMN(A1:GR1)-1)/5))*(ISNUMBER(A1:GR1)))
this function have CTRL+SHift+Enter and drag this function until your last data IF(OR((RIGHT(COLUMN(A5),1)+0)={1,2,3,4,5}),A5,--FALSE)
You Find The Columns only which end (1,2,3,4,5) , in last. You use Sum function For Add.

Excel countif(s) multiples

I'm trying to calculate the count of multiple occurrences of a figure using countif.
I have the range set but I need a calculation which can count in multiples of 50 without me having to type thousands of versions of countif (=COUNTIF(B2:B5,">=50")-COUNTIF(B2:B5,">100" etc.).
Data Count
50 1
70 1
80 1
10 0
150 3
This data should show 6 but at the moment I'm getting 4.
First you can start by making bins. you can make it with Data analysis tool or half manual
Like in the example, on A2 enter 0 and on b2 enter =a2+50
Same goes for a3 enter =b2 and last on a4 =a3+50
Now you can drag it down as much as you like.
Instaed of using countif use sumif finction. let's assume your data is on cloumn H and the values you want to sum are in column I, then on c2 enter
=SUMIFS(I:I,H:H,">"&A2,H:H,"<="&B2)
you can drag it down as much as you like.
Simply use Excels ROUNDDOWN function:
e.g. for B2: =ROUNDDOWN(A2/50,0)

Using COUNTIFS for a series of values at once

Working a step higher then COUNTIFS, I appose a challenge to write a formula without VBA code. The basic data is combined from 1000s of rows with:
Column A: rows with values from 1 to 3
Column B: rows with values from 1 to 250.
For this purpose lets say, we are looking at all cells of value "1" in column A, that suit value "5" in column B. To find all matches, we'd use COUNTIFS command.
1 1
2 5
1 5
1 7
1 10
3 45
2 12
1 2
2 1
=COUNTIFS(A1:A9;1;B1:B9;5)
The answer here is 1.
Next thing, the "5" in column B belongs to a group, e.g. group from 1 to 9. What would the best way be, to count all the matches in this example, so that for all "1"'s in column A, we'd have to find all matches with values from 1 to 9 in column B?! In the upper example that would result in "4". The obvious solution is with a series of IF commands, but that's unefficient and it easy to make a mistake, that get's easily overseen.
=COUNTIFS(A1:A9;1;B1:B9;"<="&9)
Works only as the upper limit. If I give the third criteria range and condition as ">="&1 it does not work - returns 0.
Gasper
Where the data is in A1:B9, using a lookup table in D1:E10 with letters A-J in column D and numbers 0 to 9 in column E and the following formula in B11 referencing letters entered in A11 and A12:
=COUNTIFS(A1:A9,1,B1:B9,">="&VLOOKUP(A11,$D$1:$E$10,2,FALSE),B1:B9,"<="&VLOOKUP(A12,$D$1:$E$10,2,FALSE))
works, changing the letters in A11 and A12 gives the correct count according to what they correspond to in the looku in D1:E10.
When you say give third criteria range do you mean:
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
If so then try:
=COUNTIFS(A1:A9;1;B1:B9;AND("<="&9,;">=1"))
ie have two conditional ranges with the second range having both conditions combined with AND()
Maybe what you want(ed) is:
=COUNTIFS(A:A;1;B:B;">=1";B:B;"<=9")
Almost there. I noticed that three criteria ranges and conditions work only if I use "=" sign in a condition. As soon as I use
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
it returns 0. My goal is to eventualy replace the number in a condition with a VLOOKUP command, so the final equation should be smth like
=COUNTIFS(A1:A9;1;B1:B9;"<="&VLOOKUP(...),B1:B9;">=VLOOKUP(...)")
But the "<" and ">" signs mess with this. Still looking for a solution.
This is my entire line, if it offers any further indication. The AND() commands is at the end - and it still results in 0
=COUNTIFS(INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));IF(C6="računska";1;0);INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));AND("<="&VLOOKUP($C$5;$K$203:$N$223;4;FALSE);">="&VLOOKUP($C$5;$K$203:$N$223;3;FALSE)))

Collecting the first digit of 1000 random numbers and putting each 9 digits into frequency

I have created 1000 random numbers down a spreadsheet (A1,A1000), But i would like to find the amount of times each first digit comes up.
example
12345
1354
2849
Digit 1 comes up twice,
Digit 2 comes up once
(in spreadsheet terms)
In B1 enter:
=LEFT(A1,1)
and copy down
In C1 enter:
=COUNTIF($B$1:$B$1000,ROW())
and copy down thru C9
Directly without a helping column, in B1:B9
=SUMPRODUCT(--((LEFT($A$1:$A$1000,1)+0)=ROW())*1)

Excel - find a value in two dimensions

I have a table of data like this:
a b c d
1 1 2 3 4
2 5 6 7 8
3 9 10 11 12
4 13 14 15 16
And I want a formula that finds the maximum value (16) and return its row number (4 in this case). How do I do that?
INDEX(a1:d1,MATCH(MAX(a1:h4),a1:h4,0),) ain't working :(
Sheet layout:
B1:E1: column headers
A2: A5: row headers
B2:E5: data
Array formula:
{MAX(IF(B2:E5=MAX(B2:E5);ROW(B2:E5)-1;""}
As the question asked for "d" as a result initially, the corresponding array formula is below:
{=OFFSET(A1;MAX(IF(B2:E5=MAX(B2:E5);ROW(B2:E5)-1;""));0)}
Shift-Ctrl-Enter to in a formula window to insert. Curled brackets are inserted by Excel,not by a user.
And one more humble girl's opinion:
=ADDRESS(ROW(OFFSET(A1,MAX(IF(B2:E5=MAX(B2:E5),ROW(B2:E5)-1,"")),0)),COLUMN(OFFSET(A1,0,MAX(IF(B2:E5=MAX(B2:E5),COLUMN(B2:E5)-1,"")))),4) - but entered as ARRAY formula via Ctrl+Shift+Enter, will return E5 (assuming #Jüri Ruut regions), which is simply the address of the desired cell.
Hope this attached screenshot is self explanatory?
Ok, I would program a macro like that:
Iterate over each row - find the maximum for that row.
Store the value in a array and than compute the maximum again.
Probably it would work with formulas too. Simply compute the maximum of each row in a seperate column and THEN compute the maximum of that column.
Try this array formula
=MIN(IF(A1:H4=MAX(A1:H4),ROW(A1:H4)))
confirmed with CTRL+SHIFT+ENTER
if there are multiple occurrences of the MAX value in A1:H4 then the formula will give you the first row in which it occurs

Resources