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.
Related
I'm trying to search 3 different ranges in a tab, and trying to display Yes if all three values (email address, name, x) are found in those ranges. Basically, trying to have the formula confirm that yes, all three of those inputs are somewhere in those ranges (order doesn't matter).
Maybe I should use query or regexmatch or something? Any help is appreciated
Tried this formula:
=IF(AND('Helper Calculations'!$I:$I=$A$1,'Helper Calculations'!$J:$J=L$1,'Helper Calculations'!$L:$L=$A2),"Yes","No")
Was expecting that if the search term in each of those cells ($A$1, L$1, $A2) is found somewhere in the corresponding ranges, then it would say Yes
You can try with this (you can change the use of asterisks by wrapping in AND:
=IF(COUNTIF('Helper Calculations'!$I:$I,$A$1)*COUNTIF('Helper Calculations'!$J:$J,L$1)*COUNTIF('Helper Calculations'!$L:$L=$A2),"YES,"NO")
try:
=INDEX(IF(('Helper Calculations'!I:I=A1)*
('Helper Calculations'!J:J=L1)*
('Helper Calculations'!L:L=A2), "Yes", "No"))
Took a bit more work than I expected, but I got this working. I needed to verify that all 3 values were correct in a single row (must all be correct on that one row, can't find the correct values on multiple rows).
In order to do that, I needed to use array formula, and then decided to use index match and concatenate for the 3 values.
Process described here: https://www.ablebits.com/office-addins-blog/google-sheets-index-match/
correct formula: =IF(ArrayFormula(INDEX('Helper Calculations'!$I:$I,MATCH(CONCATENATE($A$1,L$1,$A2),'Helper Calculations'!$I:$I&'Helper Calculations'!$J:$J&'Helper Calculations'!$L:$L, 0),))=$A$1,"Y"))
emails
vera#mail.com
estebangarrido#mail.c
hurtado#mail com
jmariano2mail.com
How can I pass a fuction which correct all domains to #mail.com. I know I have to use =RIGHT(,9) but when you reach the last error it does not apply
Try below formula-
=ArrayFormula(IF(A2:A="",,QUERY(SPLIT(SUBSTITUTE(SUBSTITUTE(A2:A,"mail","|"),"#",""),"|"),"select Col1",0)&"#mail.com"))
This should also work.
=INDEX(IF(LEN(A2:A),QUERY(SPLIT(SUBSTITUTE(SUBSTITUTE(A2:A,"mail","|"),"#",""),"|"),"select Col1")&"#mail.com",""))
Answer
The following formula should produce the results you desire. It assumes that the data you provide is in cells A2:A5 of your spreadsheet. If this is not the case, adjust the A2:A5 portion of the formula appropriately.
=ARRAYFORMULA(REGEXREPLACE(A2:A5,"[#|2].*","#mail.com"))
Explanation
This formula uses REGEXREPLACE to get rid of all rogue characters and replace them with #mail.com. The first argument of REGEXREPLACE is the string to be evaluated. In this case, that is the range from A2 through A5. The second argument is which characters to look for. In this case that is all characters (done using .*) that follow either an at-sign or a numeral two (done using [#|2]). The third argument is which new string to replace the found characters with. In this case that is #mail.com, the correct domain without typos.
The REGEXREPLACE is wrapped in =ARRAYFORMULA because normally REGEXREPLACE can only be used with a single cell rather than a range of cells.
Please note that this solution relies on the assumption you stated that "Everything before # or 2 is correct."
I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))
I'm trying to SUM column C based on the contents of columns A and B. Like this:
=sum(filter(C:C, (A:A="Safari")*(B:B="10.0.1")))
The above formula works. The FILTER function works as an exact match for "Safari" and "10.0.1" for columns A and B respectively.
The problem is... this only captures an exact match: "10.0.1". I need to capture multiple strings e.g. "10.0.1", "10.0.2", "10.0.3", etc.
If helpful, here's an example sheet.
I'm not sure if regex can be used in combination with a filter function. In any case, I've tried hard and failed spectacularly. So... how best to filter for multiple strings instead of exact match only?
=SUMIFS(C:C,A:A,"Safari",B:B,"10.0.*")
Please try:
=filter(C:C, (A:A="Safari")*(REGEXMATCH(B:B, "10\.0\..*")))
Notes:
filter is an arrayformlula and it has a great property: it converts all the formulas inside it into array formulas
"10.0..*" is a regex for your match. "\." will match a dot, ".*" will match any sequence of chars. Please see more syntax here.
I have a data set that looks like this: starting on A1 with "1"
1 a
2 b
3 c
4 d
Column A is an arrayformula =arrayformula(row(b1:b))
Column B is manual input
i want to query the database and finding the row of the item by match column B so i have code as such
=query("A1:B","select A where B like '%c%')
this should give me "3"
My question:
is there a way to pull the 1-4 numbers into the query line? with something like array formula row(b1:b). I don't want to waste an extra column on column A
so basically I want just the manual input and when i query it gives me the row number.
No script code please.
I've tried a few things and it didn't work.
Looking for a solutions that starts with
=query()
You can also use a formula to pull in more than one row in the dataset which matches the condition, if this is important to you:
=arrayformula(filter(row(B:B); B:B="c"))
And you can have wildcard type operators, under certain circumstances (you are going to match text or items that can look like text (so numbers can be treated as text - but boolean will need more steps); that the dataset is not huge), using regular expressions. e.g.
=arrayformula(filter(row(B:B); regexmatch(B:B, "(c|d)")))
You could also use standard spreadsheet wildcard operators, e.g.
=arrayformula(filter(row(B:B); countif(B:B, "*c*")))
Explanation: In this case, the filter will be true when countif is greater than zero, i.e. when it sees something with a letter c in it, since spreadsheets see a value greater than zero as a boolean true and so, for that row where there is a countif match, there will be a a filter match, and so it will display that row (indeed, it is a similar situation with the regexmatch creating a true when there is a match of either c or d, in the case above).
Personally, I wanted to learn regex a bit, so I would go towards the regexmatch option. But that is your choice.
You can also, of course, create the match outside of the cell. This makes it easy to create a list of matches that you want to satisfy elsewhere on the sheet. So you could have a column of words or parts of words, from Z2 downwards, and then join them together in cell Z1 for example like this
="("&join("|",filter(Z2:Z50,len(Z2:Z50)))&")"
Then your filter function would look like this:
=arrayformula(filter(row(B:B), regexmatch(B:B, Z1)))
If you want to use like operator in the query function, you can try something like this:
=arrayformula(query(if({1,0}, B:B,row(B:B)),"select Col2 where Col1 like '%c%' "))
You can also use the regular expressions in the query function, for example:
=arrayformula(query(if({1,0}, B:B,row(B:B)),"select Col2 where Col1 matches '(.*c.*|.*d.*)' "))
I'm not entirely clear on the question, but as I understand it, you want to be able to enter a formula, and have it return the row number of the matched item in a range? I'm not sure where array formulas come in.
If I've understood your question correctly, this should do the trick:
=MATCH("C",B1:B,0)
In your example, this returns 3.
Please forgive me if I've misunderstood your question.
Note: If there are multiple matches, this will return the row number for the first instance of your search.
=QUERY({A1:A,ARRAYFORMULA(ROW(A1:A))},"SELECT Col2 WHERE Col1 LIKE '%c%'")