I have an interval of data that seems like this:
I need to count how many Vs and how many Ds there are.
I already tryed with SUMIF and COUNTIF
Can someone help me?
Solution:
Join all the cells
Use Regex to replace everything other than the required character(ex.V) to null
Find the length of remaining string
Sample Formula:
=LEN(ARRAYFORMULA(REGEXREPLACE(JOIN(,A2:A9),"[^V]",)))
This Formula could also help. Just edit the range and letter according to the requirement here and you will get the exact number.
=ARRAYFORMULA(SUM(len(A$1:A)-len(SUBSTITUTE(A$1:A,"V",""))
Related
I have a google sheet column with data that looks like this. ID numbers with count suffixes. How can I transpose them horizontally into rows on a sheet sorted/grouped/filtered by their ID number into the appropriate number of columns matching their suffix number?
Sheet Link:
https://docs.google.com/spreadsheets/d/1wq3Zrh5wE_IHP2utvMeFRHrMe1qra2ppq_G7PrSt-jY/edit?usp=sharing
What I have
INV46673-1
INV46673-2
INV56184-1
INV56184-2
INV56184-3
INV56184-4
INV56184-5
INV68328-1
INV68328-2
INV68328-3
INV68328-4
INV68347-1
INV68347-2
INV68347-3
What I need
INV46673-1
INV46673-2
INV56184-1
INV56184-2
INV56184-3
INV56184-4
INV56184-5
INV68328-1
INV68328-2
INV68328-3
INV68328-4
INV68347-1
INV68347-2
INV68347-3
If sheets has an off the shelf function for this I have not been able to find it. I have tried pivot tables, Hlookup, filtered arrays etc. I am grateful for any advice I may receive. A solution that uses a fixed character count (8) will work but I would love to see something that actually uses the exact ID number.
Try the following formula-
=INDEX(SPLIT(BYROW(UNIQUE(INDEX(SPLIT(A2:A15,"-"),,1)),LAMBDA(x,JOIN("|",SORT(FILTER(A2:A15,INDEX(SPLIT(A2:A15,"-"),,1)=x))))),"|"))
Here's another approach:
=index(let(a,regexextract(A2:index(A:A,counta(A:A)),"(.*)-(\d+)"),b,unique(index(a,,1)),c,max(--index(a,,2)),makearray(counta(b),c,lambda(r,x,xlookup(index(b,r)&"-"&index(sequence(1,c),,x),A:A,A:A,)))))
I have a cell with a variable number of substrings separated by a comma.
To search:
"first,second,third"
"primero,segundo,tercero,cuarto"
"eins,zwei"
and I have a column with many strings that are composed by some of the substrings:
Column with full items
"first,second,third,fourth"
"primero,segundo,tercero,cuarto,quinto"
"primero,tercero,cuarto"
"eins,zwei,drei"
...and so on...
I would like to find the items of the Column above which has the substrings to be searched. Not a big issue when the amount of substrings is fixed but when it varies it becomes harder. I have a horrible formula that counts the number of commas and then it uses IF for each amount of substrings to search and several FIND(index(SPLIT(A4,","),2) for each substring. The formula is gigant and hard to handle.
Can you think of a better way of doing it?
Here there is an example of what I would like to do. The blue cells are the ones that should have the formula.
https://docs.google.com/spreadsheets/d/1pD9r4JF48cVSNGqA4D69lSyasWxTvAcOhWWu1xW2mgw/edit?usp=sharing
Thanks in advance!
Thank you all for your help! In the end, I used the QUERY function.
=QUERY(E:F,"select E where F contains '" & textjoin("' AND F contains '",TRUE,split(A2,",")) &"'" )
If you are interested, you can see the solution applied in the original spreadsheet :)
I need something that auto-fills for however many rows are in the spreadsheet, but I'm not sure if an array is the best way.
In my example below, I want Column C to show a 1 if the corresponding entry in Column A is unique, and a 0 if it isn't.
I had hoped it would be as easy as using ARRAYFORMULA(IF(UNIQUE(A1:A),1,0)), but forgot that IF wouldn't work with the text.
Here's my example with the most recent formula I tried.
Thank you!
Please use the following formula:
=ArrayFormula(IF(LEN(A1:A)<>0,
IF(COUNTIF(A1:A,A1:A)>1,0,1)
,""))
Functions used:
COUNTIF
ArrayFormula
LEN
You can combine ARRAYFORMULA and IF with IFERROR and COUNTIF
Sample:
=ARRAYFORMULA(IF(IFERROR(COUNTIF(A1:A,A1:A)=1,0)=TRUE,1,0))
Sorry about the title of this question, I couldn't think of a better way of phrasing it.
I have a column with time ranges in it, i.e.
08:45-17:00
06:00-10:30
09:10-14:30
08:15-16:50
10:15-17:15
15:30-20:10
09:30-13:10
etc.
What I need is a count of those occurrences that cross a comparison time range. For example with a comparison range of 11:00-15:00, the count should include any in the column that:-
(1). has a start time OR end time between 11:00 and 15:00
OR
(2). starts BEFORE 11:00 AND ends AFTER 15:00.
In the examples above the count would be 5.
This formula gives the correct result (0 or 1) for individual entries:
=sum(if(or(and(mid(I14,7,5)>"15:00",mid(I14,1,5)<"11:00"),and(mid(I14,1,5)>"11:00",mid(I14,1,5)<"15:00"),and(mid(I14,7,5)>"11:00",mid(I14,7,5)<"15:00")),1,0))
There is probably a more elegant way of writing that!
Wrapping an arrayformula around that code doesn't work.
Any help much appreciated. Thanks in advance.
This is the GoogleSheets version of Ed's formula (thx Ed)
=arrayformula(counta(filter(H9:H44,or(and(left(H9:H44,5)<="11:00",right(H9:H44,5)>="15:00"),and(left(H9:H44,5)>="11:00",left(H9:H44,5)<="15:00"),and(right(H9:H44,5)<="15:00",right(H9:H44,5)>="11:00")))))
It seems that Filter doesn't like the use of "and" and "or" as it always returns 1 as the result, regardless of the entries.
I believe this does what you want. It uses counta and filter. The '+' are or and the '*' are and. I put the date ranges in A1:A7 so adjust to your range.
=arrayformula(COUNTA(FILTER( A:A ,(((right(A:A,5)>"15:00")*(left(A:A,5)<"11:00"))+(((left(A:A,5)>"11:00")*(left(A:A,5)<"15:00")))+(((left(A:A,5)>"11:00")*(LEFT(A:A,5)<"15:00")))+((right(A:A,5)>"11:00")*(RIGHT(A:A,5)<"15:00"))) )))
I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.