I have a value in a cell like this: '2016-Week 44'
I would like to the output as '2016-44', so how could I do this?
Edit: so I have values like this
'2016-Week 44'
'2016-Week 45'
'2016-December'
If the value does not contain 'week', I want it to return NA or error
I'd solve it with regular expressions. Assuming the original values are in column A, this would be the expression:
=IF(REGEXMATCH(A1,"(?i)week"),REGEXREPLACE(A1,"([\d])\-\w+ ([\d])","$1-$2"),"empty")
(?i)week → Pre-condition: empty if not string "week", case insensitive
([\d]) → First numeric Group ($1)
\-\w+ →Character string (-) and not used text (if the word "week" does not appear the function is not processed by the first conditional)
([\d]) → Second numeric group ($2)
try simple:
=SUBSTITUTE(A1; "Week "; )
Related
I want to convert the first letter of all words in string except mentioned words. Direct "Proper" function will not work as it will capitalize all first letter string.
Example: "You can install it in a few clicks and it gives you a lot many options when it comes to changing case in Google Sheets."
I want to convert the above sentence to
"You can Install it in a Few Clicks and it Gives you a Lot Many Options when it Comes to Changing Case in Google Sheets."
ignored words: it, and, in, can, you, a, to
Thanks for your help in advance.
Vineet
Use regexreplace(), like this:
=lambda(
data, lowercaseWords,
byrow(
data,
lambda(
row,
mid(
reduce(
proper("_" & to_text(row)), lowercaseWords,
lambda(
acc, word,
regexreplace(acc, "(?i)\b" & word & "\b", word)
)
),
2, 9^9
)
)
)
)(
A2:A10,
{ "it", "and", "in", "can", "you", "a", "to" }
)
Give a try on the following formula-
=LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(FLATTEN(SPLIT(A1," ")))
For dynamic input range, try-
=MAP(A1:INDEX(A1:A,COUNTA(A1:A)),LAMBDA(lm,LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(lm)))
You can use a list of words you don't want to capitalize in a certain range you stablish with the next formula. Please change A1:A with your column or range and B1 with the cell of your expression:
=REDUCE(PROPER(B1),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,""(?i)\b"&words&"\b",words)))
If you want you can use it as an arrayformula too for a whole column of phrases B1:B:
=ArrayFormula(REDUCE(PROPER(B1:B),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,"(?i)\b"&words&"\b",words))))
I have a QUERY and, above it, I have some cells that, when filled, add conditions to the QUERY.
As my formula is today:
" and lower(Col4) contains '"& D11 & "'"
In that case from the image, when I fill the "Nº PP" filter on D11 (which is usually a string of numbers), when I type something that starts with a zero (like "040222", the case from the image) it returns everything that contains "40222".
I get zero results if I change the formula to:
" and lower(Col4) = '"& D11 & "'"
Every other case when it doesn't start with a zero, it queries correctly.
Is there a way to fix it?
it should work if you use regex:
"and lower(Col4) matches '"&TO_TEXT(D11)&"'"
I'm trying to use a query function in my google sheet.
But I have a little problem :
When I have same/less "R" than date so it display me only date and not the "R"
For example:
Another example:
And now, when I have more "R" so it's display everything:
So how can I display everything when I have same or less "R" (it can b R or any letter) ?
https://docs.google.com/spreadsheets/d/1svXFqHVtbgMfHPZjxS3X9AKW679AqrVyMDySay2lzfw/edit?usp=sharing
Thanks for your help
Try
=QUERY(arrayformula(to_text(H1:J6)),"WHERE Col3 IS NOT NULL " ,0)
the problem comes from a combination of string and numeric value in the same column (date is numeric), query does not work well and you have to convert data into strings. Because the source is now a function, you will have to use Colx instead of letter of column.
I am trying to learn Regex and I have scenario where I thought I can use the same. I have a set of strings in the below format(as shown in the table) from which I need to extract each substring around joining operator "and", "or", "not". For eg:- "some column name1 = some value1" as one such substring from first string.
After that I need to extract left hand side string and right hand side string of operators "like", "=", "<", ">". In the above example it would give "some column name1" as one substring and "some value1" as another substring along with operator as "=".
some column name1 = some value1 and some column name2 < another value2 or some column name 3 > value3 not
column name 4 = value4 and name5 = value5
columnA = 324324
columnB like a text
value text
Since I am new to Regex, this is what I have tried till now but it doesn't seem to give me all the values around these operators. Once this works, I am thinking I can apply similar regex with operators as "like", "=", "<", ">" on the resulting substrings to get final output.
(.*?)\b(and|or|not)
When I try the above regex on the first example, this part "name5 = value5" is missing after matching.
(.+?)(and|or|not)(.+)
When I try this one, it matches the first substring but rest of them are matched as a single substring instead of splitting those again.
Please note that I was able to use split operation and give "and|or|not" as separator to get array of substrings however I am trying to see if I can directly get these matched substrings from the given string just for learning regex(This answer says it is possible to do using Regex). I have explored stackoverflow for similar questions but none of the solutions worked in my case. The language in my case is Objective C/Swift.
You may add an end of string anchor $ as an alternative to the delimiters.
(.*?)(?:\b(and|or|not)\b|$)
^^
See the regex demo.
If your string contains line breaks, you must make . match them by adding (?s), a DOTALL modifier, at the pattern start.
I have the following google sheet where:
Col a= quantities
Col b= product codes, which i´ve split between C and H.
I want to know the quantity according to different "filters"... this filters are the fields between C11 and H11, and they are optional. There are 6 possible filters.
It works using =QUERY formula located in H12 and it returns the sum of quantity values where the filters match...
BUT there´s the possibility of leaving a filter empty to get "all"...
the query is as follows:
=QUERY(A1:H7, "select sum(A) where C contains '"&C11&"' and lower(D) contains lower('"&D11&"') and E contains '"&E11&"' and lower(F) contains lower('"&F11&"') and lower(G) contains lower('"&G11&"') and lower(H) contains lower('"&H11&"') ",-1)
My problem is with the match type: where C contains '"&C11&"' and...
instead of using "contains" it should compare using "matches". this way it would count like it should, but then it won´t accept empty filters.
How can I get it to count only if the field is filled??
What´s wrong with the filter right now? It´s counting "4" matches because model matches "1" happens when model is 1 or 21, also with column D where i´m looking for value X and is also counting value XN as it contains "X". if formula is changed to "matches" instead of "contains", it won´t allow me to leave it blank.
Thank you!
Karl_S formula is great, but it does not sum the quantities in column A. Adapting his approach to SUMIFS seems to do it:
=SUMIFS(A2:A7,C2:C7, IF(ISBLANK(C11), "<>" ,C11),D2:D7, IF(ISBLANK(D11), "<>" ,D11),E2:E7, IF(ISBLANK(E11), "<>" ,E11),F2:F7, IF(ISBLANK(F11), "<>" ,F11),G2:G7, IF(ISBLANK(G11), "<>" ,G11),H2:H7, IF(ISBLANK(H11), "<>" ,H11))
Use this formula instead:
=COUNTIFS(C2:C7, IF(ISBLANK(C11), "<>" ,C11), D2:D7, IF(ISBLANK(D11), "*",D11), E2:E7, IF(ISBLANK(E11), "<>",E11), F2:F7, IF(ISBLANK(F11), "*",F11), G2:G7, IF(ISBLANK(G11), "*",G11), H2:H7, IF(ISBLANK(H11), "*",H11))
If one of the options is blank, it will match all items in that column. Otherwise it should do an exact match.