When I perform this function, it works:
=Query(CRM!1:1085,"Select B where D contains 'FirstName LastName' ",4)
When I perform this one, where B31 is where the text "FirstName LastName" is located in the sheet, the output is only ONE of the many results:
=Query(CRM!1:1085,"Select B where D contains '&B31&' ",4)
I want to be able to use the cell rather than write the quoted text in the formula. This is because I need to quickly replicate the formula for many different values. Also because it needs to be automated in case of changes in the source.
B31 is interpreted as literal string, when you use just 'B31'. You need to use double quotes along with single ones and concatenate:
'"&B31&"'
Related
I am trying to filter(query()) some specific columns into a spreadsheet where I do some automatic calculations. However, there are 8 or so specific strings that I don't need and clutter the calculations page. I have a list of these strings that I don't need but I can't seem to EXCLUDE these strings from the filter(query()) without creating a 15 line block of text.
What I've Tried:
=FILTER(QUERY(A:C,"select A,C"),QUERY(A:C,"select A")<>D2,D3,D4,D5)
=FILTER(QUERY(A:C,"select A, C"),QUERY(A:C,"select A")<>{D2,D3,D4,D5}) - I have also tried this one joining the text w/ a "," so that there is one value
=FILTER(QUERY(A:C,"select A, C"),QUERY(A:C,"select A")<>D2) - What is silly is THIS ONE VALUE works, but I cant add multiple values without adding 7 more conditions to the filter which would exclude the values that I need excluded, but I would have to change the formula manually and it would be monstrous when I keep adding strings to remove.
The goal is to be able to be able to add another string to a separate cell and have that be excluded as well.
Here is the google sheet: https://docs.google.com/spreadsheets/d/1u-Po1Oae4MTYU10o_-1Yu0s9Ras9JUn4-SFzTkmMldI/edit?usp=sharing
Suggestion
Perhaps you can try using REGEXMATCH so you could add multiple words to be matched but in the reverse way (via placing the REGEXMATCH in a NOT function) to FILTER your data more efficiently as seen below:
=FILTER(QUERY(Sheet1!A:C,"select A, C"),NOT(REGEXMATCH(Sheet1!A:A,"Value 7|Value 3|Value 10|Value 8")))
Alternatively, you could also reference the range of cells you want to exclude in the REGEXMATCH via JOIN function like:
=FILTER(QUERY(Sheet1!A:C,"select A, C"),NOT(REGEXMATCH(Sheet1!A:A,JOIN("|",D2:D5))))
[UPDATE]
If you're using an IMPORTRANGE in your actual sheet formula, then you would need to structure it like this sample. The REGEXMATCH formula also contains a range:
=FILTER(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/XXXXXX","Sheet1!A:C"),"select Col1, Col3"),NOT(REGEXMATCH(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/XXXXXX","Sheet1!A:C"),"select Col1"),"Value 7|Value 3|Value 10|Value 8")))
Demo
Sample Test
The referenced Sheet 1
References
REGEXMATCH
NOT
JOIN
I have two different sheets, with two of the same ranges (age). I want to combine these two separate ranges into one on a different sheet. Current formula / function I am using:
={(importrange("https...", "Sheet1!A2:A100"));(importrange(""https...", "Sheet2!A2:A100"))}"))
What am I doing wrong?
I was able to bring in one range at a time with this formula / function:
=IMPORTRANGE("https...", "Sheet1!A2:A100")
=IMPORTRANGE("https...", "Sheet2!A2:A100")
but I need them to be in one column together (the order does not matter, I just need the values to be pulled across).
Try two IMPORTRANGE functions within one formula separated by a semi-colon and wrapped in braces (e.g. { and } that you type yourself)
={IMPORTRANGE("https://docs.google.com/spreadsheets/d/1mYWnO8vzyb5o4jzp-Ti-369nSyQoCfg-WzqaaTb94tE", "Sheet1!A2:A10");IMPORTRANGE("https://docs.google.com/spreadsheets/d/1mYWnO8vzyb5o4jzp-Ti-369nSyQoCfg-WzqaaTb94tE", "Sheet2!A2:A")}
If you do not have a set number of rows in the source sheet1 (e.g. A2:A100), then the retrieved data from sheet2 will start on the 101st row with blanks above it. To get around this, concatenate a dynamic 'last populated' row number onto the range string.
={IMPORTRANGE("https://docs.google.com/spreadsheets/d/1mYWnO8vzyb5o4jzp-Ti-369nSyQoCfg-WzqaaTb94tE", "Sheet1!A2:A"&match(1E+99, IMPORTRANGE("https://docs.google.com/spreadsheets/d/1mYWnO8vzyb5o4jzp-Ti-369nSyQoCfg-WzqaaTb94tE", "Sheet1!A:A")));IMPORTRANGE("https://docs.google.com/spreadsheets/d/1mYWnO8vzyb5o4jzp-Ti-369nSyQoCfg-WzqaaTb94tE", "Sheet2!A2:A")}
source link
destination link
What am I doing wrong?
You have a couple of double inverted commas too many and unmatched parentheses (also some unnecessary spaces and parentheses). Following should work, with granting authorisation if required.:
={importrange(" k e y 1 ","Sheet1!A2:A100");importrange(" k e y 2 ","Sheet2!A2:A100")}
It might help to compare 'yours' and 'mine' in a word processor and fixed width font.
In a Google Sheets spreadsheet, I have the cell A1 with value "people 12-14 ABC". I want to extract the exact match "ABC" into another cell. The contents of cell A1 can change, e.g. to "woman 60+ ABCD". For this input, I would want to extract "ABCD". If A1 was instead "woman 12-20 CAE", I would want "CAE".
There are 5 possible strings that the last part may be: (ABC, ABCD, AB, CAE, C), while the first portions are very numerous (~400 possibilities).
How can I determine which of the 5 strings is in A1?
If the first part "only" has lower case or numbers and the last part "only" UPPER case,
=REGEXREPLACE(D3;"[^A-E]";)
Anchor: Space
=REGEXEXTRACT(A31;"\s([A-E]+)$")
If you can guarantee well-formatted input, this is simply a matter of splitting the contents of A1 into its component parts (e.g. "gender_filter", "age range", and "my 5 categories"), and selecting the appropriate index of the resultant array of strings.
To convert a cell's contents into an array of that content, the SPLIT() function can be used.
B1 = SPLIT(A1, " ")
would put entries into B1, C1, and D1, where D1 has the value you want - provided your gender filter and age ranges.
Since you probably don't want to have those excess junk values, you want to contain the result of split entirely in B1. To do this, we need to pass the array generated by SPLIT to a function that can take a range or array input. As a bonus, we want to sub-select a part of this range (specifically, the last one). For this, we can use the INDEX() function
B1 = INDEX(SPLIT(A1, " "), 1, COUNTA(SPLIT(A1, " ")))
This tells the INDEX function to access the first row and the last column of the range produced by SPLIT, which for the inputs you have provided, is "ABC", "ABCD", and "CAE".
Unfortunately the data I'm working with requires quotation marks, as it is entered into another system afterwards which requires it.
I'm trying to collect statistics, and need to count these entries. The only thing they have in common is they are wrapped in quotation marks.
I'm trying to use =COUNTIF($C3:$C, """) but it keeps changing it to =COUNTIF($C3:$C, "")"").
Is there a way to escape this so that i can count cells that contain a quotation mark (")?
Like Robin said, the most straightforward way to reference quotes is with the character code - for the double quote character it's CHAR(34). One possible solution to this uses QUERY(), like so:
=QUERY($C3:$C, "Select count(C) where C contains '" & CHAR(34) & "' label count(C) ''", 0)
You can omit the label count(C) '' at the end if you're okay with it displaying a header cell, but adding it on contains the entire result to a single cell.
Try this it seems to do what you want to do:
=COUNTIF(C3:C, "'*")
note the single quote mark.
I have a column in open office like this:
abc-23
abc-32
abc-1
Now, I need to get only the sum of the numbers 23, 32 and 1 using a formula and regular expressions in calc.
How do I do that?
I tried
=SUMIF(F7:F16,"([:digit:].)$")
But somehow this does not work.
Starting with LibreOffice 6.4, you can use the newly added REGEX function to generically extract all numbers from a cell / text using a regular expression:
=REGEX(A1;"[^[:digit:]]";"";"g")
Replace A1 with the cell-reference you want to extract numbers from.
Explanation of REGEX function arguments:
Arguments are separated by a semicolon ;
A1: Value to extract numbers from. Can be a cell-reference (like A1) or a quoted text value (like "123abc"). The following regular expression will be applied to this cell / text.
"[^[:digit:]]": Match every character which is not a decimal digit. See also list of regular expressions in LibreOffice
The outer square brackets [] encapsulate the list of characters to search for
^ adds a NOT, meaning that every character not included in the search list is matched
[:digit:] represents any decimal digit
"": replace matching characters (every non-digit) with nothing = remove them
"g": replace all matches (don't stop after the first non-digit character)
Unfortunately Libre-Office only supports regex in find/replace and in search.
If this is a once-only deal, I would copy column A to column to B, then use [data] [text to columns] in B and use the - as a separator, leaving you with all the text in column B and the numbers in column C.
Alternatively, you could use =Right(A1,find("-",A1,1)+1) in column B, then sum Column C.
I think that this is not exactly what do you want, but maybe it can help you or others.
It is all about substring (in Calc called [MID][1] function):
First: Choose your cell (for example with "abc-23" content).
Secondly: Enter the start length ("british" --> start length 4 = tish).
After that: To print all remaining text, you can use the [LEN][2] function (known as length) with your cell ("abc-23") in parameter.
Code now looks like this:
D15="abc-23"
=MID(D15; 5; LEN(D15))
And the output is: 23
When you edit numbers (in this example 23), no problem. However, if you change anything before (text "abc-"), the algorithm collapses because the start length is defined to "5".
Paste the string in a cell, open search and replace dialog (ctrl + f) extended search option mark regular expression search for ([\s,0-9])([^0-9\s])+ and replace it with $1
adjust regex to your needs
I didn't figure out how to do this in OpenOffice/LibreOffice directly. After frustrations in searching online and trying various formulas, I realised my sheet was a simple CSV format, so I opened it up in vim and used vim's built-in sed-like feature to find/replace the text in vim command mode:
:%s/abc-//g
This only worked for me because there were no other columns with this matching text. If there are other columns with the same text, then the solution would be a bit more complex.
If your sheet is not a CSV, you could copy the column out to a text file and use vim to find/replace, and then paste the data back into the spreadsheet. For me, this was a lot less frustrating than trying to figure this out in LibreOffice...
I won't bother with a solution without knowing if there really is interest, but, you could write a macro to do this. Extract all the numbers and then implement the sum by checking for contained numbers in the text.