Countif with case sensitive google-sheets - google-sheets

I'm trying to do a case-sensitive count in Google Sheets.
For example, I have these values :
A
A
A
B
a
b
The countif function :
=COUNTIF(A1:A6;"A") give me 4 whereas I expected to have the number 3
All results :
Letter/Word
Number give by countif
Expected number
A
4
3
a
4
1
b
2
1
B
2
1
How could I create a case-sentive countif ?

There are a couple of ways to achieve that. Here's one way:
=SUMPRODUCT(REGEXMATCH(A1:A6, "A"))
Or, depending on your locale:
=SUMPRODUCT(REGEXMATCH(A1:A6; "A"))

Related

Google Sheets: Query and list the last 5 values in a column if the column contains a number

I want to use Sparkline for a spreadsheet to show a trend of the last 5 soccer matches, where A and B are the goals, and C are the resulting points.
In column C, the points are only generated if values are entered for the goals and goals conceded, i.e. the columns are not empty.
A (Goals)
B (Conceded)
C (Points)
4
4
1
4
4
1
4
4
0
3
4
4
1
0
4
0
As you see, in row 3, column c is empty.
What I basically try to achieve, is to create a list where the last 5 entries which are not empty / null, are listed:
C (Points)
1
1
3
1
0
Is used this formula, but it somehow does not work
=query(J15:J114,"select * offset "&count(J15:J114)-5)
shorturl.at/gHPY9 (example result picture)
Tried to find a solution myself, but am stuck.
Best,
Feal
Use query() with a where clause, like this:
=query(
J15:J114,
"where J is not null
offset " & max(0, count(J15:J114) - 5),
0
)

List all numbers between 0 and 10^n containing repdigits in google sheets

In Google sheets How to get a list of all repdigits numbers between 0 and 10^n.
Example: We have the input n in B1 set to 3 therefore our numbers are between 0 and 10^3 alternatively between 0 and 1000
We should get this list of repdigits.
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999
Requirments
Less references
Shortest formula
Efficient processing
If possible without lambda and its helpers
Note
If cell or row/column limit is reached is acceptable not to join the result.
More examples
n
Output
3
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999
4
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999
5
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999
6
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999
7
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999
8
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999
9
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999
10
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999,1111111111,2222222222,3333333333,4444444444,5555555555,6666666666,7777777777,8888888888,9999999999
11
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999,1111111111,2222222222,3333333333,4444444444,5555555555,6666666666,7777777777,8888888888,9999999999,11111111111,22222222222,33333333333,44444444444,55555555555,66666666666,77777777777,88888888888,99999999999
12
11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999,1111111111,2222222222,3333333333,4444444444,5555555555,6666666666,7777777777,8888888888,9999999999,11111111111,22222222222,33333333333,44444444444,55555555555,66666666666,77777777777,88888888888,99999999999,111111111111,222222222222,333333333333,444444444444,555555555555,666666666666,777777777777,888888888888,999999999999
Repdigits are multiples of Repunits like 11, 111. We can easily create Repunits of 1 by REPeaTing 1 and supplying a SEQUENCE to number of times argument of REPT. Once created, just multiply them by sequence of 1..9 and JOIN them using ,.
Snippet(for 3):
=ARRAYFORMULA(TEXTJOIN(",",,REPT("1",SEQUENCE(3-1,1,2))*SEQUENCE(1,9)))
This question could phrased like:
How to get all repdigit, monodigit or numbers that consist of the same digit between 0 and 10^n
Use this formula
=ArrayFormula(
LAMBDA(n, REGEXEXTRACT(TEXTJOIN(",",1,BYROW(SEQUENCE(n), LAMBDA(r, TEXTJOIN(",",1,REPT(SEQUENCE(9),r))))),"11.+"))
(B1))
Explanation
We are repeating each number in the sequence {1;2;...n} 1,2,...n times and joining with comma , and join all with comma ,.
In other words:
For each number in {1;2;...n} REPT once and twice and ... n times then join all with a comma.
Used formulas help
ARRAYFORMULA - LAMBDA - REGEXEXTRACT - TEXTJOIN - BYROW - SEQUENCE - REPT
not sure how serious you are with n but try:
={""; INDEX(QUERY(FLATTEN(QUERY(TRANSPOSE(REPT(
SEQUENCE(1, 9), SEQUENCE(C1, 1, 2))&","),,9^9)),,9^9))}
where C1 = 1000 -----> (10^1000)
and if you are brave enough, change 1000 to 10000 or 50000 :)

Google Sheet - It's possible to array sum function in the following condition?

Would it be possible to use arrayformular for this condition?
Sum all the rows that PID are the same, the result should be as in the image.
I tried this code, but I think it's too long, and if the PID exceed over 20 rows, it would not work.
=IF(A3<>A2,BJ3+IF(A3=A4,BJ4,0)+IF(A3=A5,BJ5,0)+IF(A3=A6,BJ6,0)+IF(A3=A7,BJ7,0)+IF(A3=A8,BJ8,0)+IF(A3=A9,BJ9,0)+IF(A3=A10,BJ10,0)+IF(A3=A11,BJ11,0)+IF(A3=A12,BJ12,0)+IF(A3=A13,BJ13,0)+IF(A3=A14,BJ14,0)+IF(A3=A15,BJ15,0)+IF(A3=A16,BJ16,0)+IF(A3=A17,BJ17,0)+IF(A3=A18,BJ18,0)+IF(A3=A19,BJ19,0)+IF(A3=A20,BJ20,0)+IF(A3=A21,BJ21,0)+IF(A3=A22,BJ22,0),0)
With a table like this :
ID
Value
1
5
1
10
2
5
2
10
2
15
You have an expected output of :
ID
Value
Sum
1
5
15
1
10
blank
2
5
30
2
10
blank
2
15
blank
It is achievable with this formula (just drag it in your sum column) :
=IF(A2=A1,"",SUMIFS(B$2:B$12,A$2:A$12,A2))
It check if the ids are the same and then sum them, but only show them on the row where the id first appears
Found it on google by searching google sheets sum group by
The following in C2 will generate the required answer without any copying-down required:
=arrayformula(if(len(A2:A),ifna(vlookup(row(A2:A),query({row(A2:B),A2:B},"select min(Col1),sum(Col3) where Col2 is not null group by Col2"),2,false)),))
We are making a lookup table of grouped sums against the first row of each 'P#' group using QUERY, then using VLOOKUP to distribute the group sums to the first row in each group. Probably also doable using a SCAN/OFFSET combination as well, I think.

Count number of rows for each type in google spreadsheet

A B C
1 4 Apple
2 5 Orange
3 6 Apple
1 4 Orange
2 4 Apple
3 4 Banana
I want to count each type of column C(if possible also plot it), ie output should be
Apple 3
Orange 2
Banana 1
Just more to a new columns and paste the folloing in its header:
=query(H2:H,"select H, count(H) where H != '' group by H order by count(H) desc label H 'Fruit'", 0)
It is show something like your expection in new two columns beside the original data
As an alternative to the solution already provided, you can make use of UNIQUE and COUNTIF.
Use UNIQUE in order to extract the names for each fruit from the C column
=UNIQUE(C1:C)
Use COUNTIF within an ARRAYFORMULA in order to count the number of times each fruit is present in the C column and later drag it down the E column:
=ARRAYFORMULA(COUNTIF(C1:C,D1))
Reference
UNIQUE Function;
COUNTIF Function.

vlookup return array (formula only, no code please)

I have a table like so:
A B C D
1 3 2 1
2 3 2 1
3 0 2 2
I want to vlookup the first column so that it returns the 3 columns after.
For example if I look up 2, i want the return to be 3 2 1.
i need it in one formula because it will go into a sumproduct expression.
Does not have to be a vlookup. I just need something that will return me an array though some type of indexing or lookup.
One of the ways to achieve this is query. So for the data given by you (A, B, C are column), you can use the following formula to get all three columns for the lookup value 2
=QUERY($A$1:$D$3,"select B,C,D where A = 2")
Then you can apply any aggregate function on top of this too. For eg:
=sum(QUERY($A$1:$D$3,"select B,C,D where A = 1"))
Check this link

Resources