Creating a google sheets sumif with case-insensitive criteria - google-sheets

I am trying to create a SUMIF with a case-insensitive criteria (.ie contains, but not necessarily match).
Currently testing for a date range and one criteria. I would like to add one more criteria that checks for text contained in a cell in column 'Time Entry'!$J$2:$J$5993.
SUMIFS('Time Entry'!$G$2:$G$5993,'Time Entry'!$K$2:$K$5993,$A6,'Time Entry'!$D$2:$D$5993,">=" & $A$2,'Time Entry'!$D$2:$D$5993,"<=" & $B$2)
Any ideas?

SUMIF is already case insensitive, if you want to match something "contains, but not necessarily match" you can use wildcards.
? to match any single character
* to match any sequence of characters
So this will match any cell that contains "christmas" (or "Christmas" or "CHristmas" etc.)
=SUMIF(A1:A99,"*christmas*",B1:B99)
If you want to get your search value itself from a cell you can write it like this (if your value was in C1):
=SUMIF(A1:A99,"*"&C1&"*",B1:B99)
If your are looking for an actual question mark or asterisk, escape it with the tilde like this: ~? or ~*.
(late answer and not sure if the OP was looking for this but maybe conventient for future visitors)

Related

Capitalize only words with more than 2 characters on Google Sheets

How can I capitalize only words with more than a specific count of characters? Google Sheets formula PROPER capitalizes all the words without any exclusions. For example, I would like to omit the capitalization of an acronym such as "PC" or "RAM" that is contained within a string in a cell.
Capitalize All and exclude from a list
To be able to PROPER()/Capitalize the input of words and exclude others:
Use this formula, but first we need the excluded list "Acronyms excluded".
=ArrayFormula(IF(
REGEXMATCH(TEXTJOIN("^_~",,UNIQUE($D$2:$D)), UPPER(A2:A))<>TRUE,PROPER(A2:A),A2:A))
Capitalize only words more than 2 charachters long
=ArrayFormula(IF(A2:A="",,
IF(LEN(UPPER(A2:A))<=2,
UPPER(A2:A),PROPER(A2:A))))
I may have been overthinking this by a mile, but try:
Formula in B1:
=INDEX(SUBSTITUTE(TEXTJOIN("",0,IF(LEFT(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"))="♣",SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"),PROPER(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|")))),"♣",""))
The point here is that \b(RAM|[A-Za-z]{1,2})\b would capture any 1-2 character word made of word-characters between word-boundaries or RAM. Now you can add any exclusion into the alternation of the pattern through concatenating more |. The replacement includes a backreference to the capture group to encapsulate the substring between a delimiter to split on and a leading unique character. The IF() will then check whether or not any element from the resulting SPLIT() needs to be processed with Proper() or not.
Note: Word-boundaries like \b may not be safe when you'd have data like hello-pc and you'd want this to be processed with PROPER(). A small adjustment to the formula is then needed.

Is it possible to assign conditional formatting to a named range in Google Sheets?

I'd like to apply a conditional formatting rule to a named range. Is that even possible? How do I do that? When trying to enter the Name of the Range to the Field where you set up the range the rule applies to it won't accept my input.
Also with INDIRECT it does not work:
this is not possible in Google Sheets
for the custom formula you need to wrap it into INDIRECT formula like:
I think it is not possible, it is not documented in official docs.
Range names:
Can contain only letters, numbers, and underscores.
Can't start with a number, or the words "true" or "false."
Can't contain any spaces or punctuation.
Must be 1–250 characters.
Can't be in either A1 or R1C1 syntax. For example, you might get an error if you give your range a name like "A1:B2" or "R1C1:R2C2."
The following works for my specific use case, where the named range is an "unknown" number of rows.
In this case, A1 is a column heading, and is not part of the named range.
A2:A5 is currently assigned to the named range, CitationType.
Conditional formatting is applied to A1:A based on the formula:
=and(row(A1)>1,row(A1)<=1+rows(indirect("CitationType")))
I did not find an easy way (without scripting) to get the address details of a named range, allowing for "arbitrary" usage in conditional formatting.
For custom formulas in Sheets conditional formatting, the formula usually accesses a column value in the first row of the format range. Named range values can be used in custom formulas using INDIRECT function.
example from my case ... a list of "brackets" in a tournament. Bracket rows are coloured depending on what bracket the row is for (e.g. brackets 1-10), that value is in the E column.
The formula specifies the appropriate column in the first row of the range (row is relative as conditional formatting iterates over the range). Since my range is B2:G1005, the formula references cell $E2 (the bracket ID) and compares it to the bracket id stored in a named-range location (BID_1), so custom formula is:
=$E2=INDIRECT("BID_1")
(if bracket matches the ID assigned to bracket 1 -- colour the cells grey with bolded black text).
Screenshot of conditional formatting using a named range

Google spreadsheets conditional formatting if text contains numbers

I have a sheet containing my weekly schedule. Only school cells have a room number in it, so how do I format the cells to color only the ones that contain a number.
note: Actually, the room number is a number in range(A:E) followed by a three digits number in range(000:499). Ex.:(A433, B166, D254)
I tried: Text contains"(A:F)(000:444)" but it didn't work.
EDIT:
For some reason, "=REGEXMATCH(B2, "[A-F][0-9]{3}")" worked. Could anyone tell me why? I tried replacing B2 by B1, but then it didn't work. Does it have anything to do with the fact that B1 is a weekday, and so does not contain REGEXP(B1,"[A-F][0-9]{3}) returned false.
What seemed more logical to me was "=REGEXMATCH(B2:F22, "[A-F][0-9]{3}")" To apply this function in range B2 to F22. What am I missing here?
In order to match patterns, you'll need to use regular expressions. Since the standard Conditional Formatting options don't include regular expressions, you'll need to choose "Custom formula is" and then use REGEXMATCH, which returns a Boolean value.
If you really want to look for the specific room number format you mentioned, then you would use the formula:
=REGEXMATCH(A1, "[A-E][0-9]{3}")
But if you just want to look for any numbers, you can use
=REGEXMATCH(A1, "[0-9]+")
In both cases, the text you're checking is in cell A1
You might try Conditional Formatting with a custom formula rule of the type:
=if(isnumber(A1),1,regexmatch(A1,"\d"))
The above was an attempt to respond to:
Google spreadsheets conditional formatting if text contains numbers
A more particular fit for the stated room number style would be:
=REGEXMATCH(A1,"[A-F]\d\d\d")
where the first character is any of the first six letters of the alphabet, if capitalised, followed by three instances of any number.

Sheets: use FILTER for multiple strings instead of exact match only?

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.

pulling row number into query google spreadsheet

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%'")

Resources