I am planning to use checkboxes to filter search results from my Google Fusion Tables Map. I want an OR operator to be implemented in my query. I tried to look for solutions and I found this page. It only lists these operators: >, <, >=, <=, = and LIKE, MATCHES (equivalent to LIKE), STARTS WITH, ENDS WITH, CONTAINS, CONTAINS IGNORING CASE, DOES NOT CONTAIN, NOT EQUAL TO, IN.
I need an OR operator. I need to retrieve rows that contain a series of characters. First, it will look for columns that have a Rating equivalent to 1, 2, 3, 4 or 5. And then look for columns that have Price equivalent to $, $$, $$$, $$$$, $$$$$.
Any alternative ways to do this?
Related
I am trying to find a formula that will give me the count of unique dates a persons' name appears in one of two different columns and/or both columns.
I have a set of data where a person's name may show up in a "driver" column or a "helper" column, multiple times over the course of one day. Throughout the day some drivers might also be helpers and some days a driver may come in for duty but only as a helper. Basically all drivers can be helpers, but not all helpers can be drivers.
I've attached a link to a sample sheet for more clarity.
https://docs.google.com/spreadsheets/d/1GqNa1hrViX4B6mkL3wWcqEsy87gmdw77DhkhIaswLyI/edit?usp=sharing
I've created a REPORTS tab with a SORT(UNIQUE(FLATTEN)) Formula to give me a list of the names that appear in the DATA Tab.
I'm looking for a way to count the unique dates a name from the name (Column A of the REPORTS Tab) appears in either of the two columns (Column B and/or C of the DATA Tab) to determine the total number of days worked so I can calculate the total number of days off over the range queried.
I've tried several iterations of countif, countunique, and countuniqueifs but cannot seem to find a way to return the correct values.
Any advice on how to make this work would be appreciated.
I think if you put this formula in cell b7 you'll be set. You can drag it down.
=Counta(Unique(filter(DATA!A:A,(DATA!C:C=A7)+(DATA!B:B=A7))))
Here's a working version of your file.
For anyone interested, Google Sheets' Filter function differs slightly from Excel's Filter function because Sheets attempts to make it easier for users to apply multiple conditions by simply separating each parameter with a comma. Example: =filter(A:A,A:A<>"",B:B<>"bad result") will provide different results between the Sheets and Excel.
Excel Filter requires users to specify multiple conditions within parenthesis and denote each criterion be flagged with an OR condition with a + else an AND condition with a multiplication sign *. While this can appear daunting and bizarre to multiply arrays that have text in it, it allows for more flexibility.
To Google's credit, if one follows the required Excel Syntax (as I did in this answer) then the functions will behave the same.
delete what you got and use:
=QUERY(QUERY(UNIQUE({DATA!A:B; DATA!A:A, DATA!C:C}),
"select Col2,count(Col1),"&D2&"-count(Col2)
where Col2 is not null
group by Col2"),
"offset 1", 0)
This is the formula I am working on right now:
=FILTER(Data!A:K, SEARCH("Gretsch", Data!F:F)+SEARCH("Krutz", Data!F:F))
I'm trying to bring in both rows that include "Gretsch" and rows that include "Krutz". Just using one of those instead of both works just fine, and using keywords that the other has included in it's results (for example, searching just Gretsch brings up 10 or so (out of the 100+) products that include "Streamliner" in the F Column, as well as Gretsch, so using this formula:
=FILTER(Data!A:K, SEARCH("Gretsch", Data!F:F)+SEARCH("Streamliner", Data!F:F))
brings up the 10 or so products with both, but I'm looking for one OR the other, so why is that '+' acting like an AND operator instead? Am I just completely off base?
SEARCH returns a number: the starting position where a string is found within another string. It's not a simple 1 like other tests for TRUE, and there is no 0 case (i.e., FALSE) as you have it written. In addition, if either SEARCH does not find the target string, it returns an error; and a number plus an error... returns an error (which is not TRUE and therefore will not be included in the FILTER).
A better approach to achieving OR with FILTER:
=FILTER(Data!A:K, REGEXMATCH(LOWER(Data!F:F),"gretsch|krutz"))
The pipe symbol ("|") means OR in this context, and you may list as many pipe-separated strings as you like. Notice that the search range is wrapped in LOWER and that the terms to search are also lowercase; this assures the same kind of caps-agnostic search you were looking for with SEARCH.
By the way, based on your other recent post, you can also use REGEXMATCH with NOT, e.g.:
=FILTER(Data!A:K, REGEXMATCH(LOWER(Data!F:F),"gretsch|krutz"), NOT(REGEXMATCH(LOWER(Data!F:F),"case")))
One additional note: Your post is tagged "Excel" and "Google Sheets." The formulas I've proposed will only work with Google Sheets. In most cases by far, it is best to tag a post here with either "Excel" or "Google Sheets" but not both, since the differences are substantial between the two.
try:
=QUERY(Data!A:K, "where lower(F) contains 'gretsch'
or lower(F) contains 'krutz'")
I wrote a =QUERY formula in Google spreadsheet. However I would like to copy not only the values of the cells but also the embedded links from the range of cells I am performing the query on. This is what I wrote:
=QUERY('Tab'!6:1963,"select C where (E='Major' and D >= now())")
There must be a way to tell the query to bring the URL as well along the content of the cells.
The query function only supports certain data types:
Supported data types are string, number, boolean, date, datetime and timeofday.
It doesn't handle other things one might embed into a spreadsheet, such as images or hyperlinks. (Hyperlinks are coerced to strings.) After all, the query language is not something Sheets-specific, it has its own data models that interact with Sheets only to an extent.
A solution is to use filter instead of query, if possible. It can do many of the things that query does. For example,
=QUERY(Tab!6:1963,"select C where (E='Major' and D >= now())")
can be replaced by
=filter(Tab!C6:C1963, (Tab!E6:E1963="Major") * (Tab!E6:E1963 >= now()))
which will return the links as expected. (And even images inserted with =image() if you got them.) The multiplication operator is logical and in the filter formula.
I know this is three years later, but I ran into this issue and my query would have converted to a complicated nest of FILTER and SORT functions. So I ended up doing something like this: ARRAYFORMULA(VLOOKUP(QUERY('Tab'!6:1963,"select C where (E='Major' and D >= now())"),C:C,1,FALSE))
Which worked.
Often this question comes into play with IMPORTRANGE. And Google's official answer does not really help (i.e. QUERY only works with strings, etc.). It is possible to give the filter range as an imported range, too, then it works:
=FILTER(IMPORTRANGE("XXX","Data!A1:A),
IMPORTRANGE("XXX","Data!B1:B")>0)
where column A is the data you want to import and column B is the filter
I've searched all over and this simple principle is apparently not so simple.
BTW I'm using Google Sheets which as you probably know has most of the same functionality as Excel, plus an extra function that might be useful in my case: COUNTUNIQUE()
My "Criteria" is two-fold and required for two different expressions:
Count the unique values that "contain" a string.
Count the unique values that "don't contain" a string.
Consider this data:
A
1 snapple
2 snapple
3 grapple
4 orange
5 orange
6 peach
Criteria 1: Say I want to count the unique values in Column A that contain the word "apple."
In the data above, it should render "2," knowing it should void duplicates.
Criteria 2: Say I want to count the unique values in Column A that don't contain the word "apple."
In the data above, it should render "2," knowing it should void duplicates.
Here's a sheet doc to test: https://docs.google.com/spreadsheets/d/1JYZIhZmSuoWoGvmTFFcBAD1EUQVWvosqBQzkGsbwaOI/edit?usp=sharing
Criteria 1:
=COUNTUNIQUE(IFERROR(QUERY(A:A,"select A where A contains 'apple'",0)))
Criteria 2:
=COUNTUNIQUE(IFERROR(QUERY(A:A,"select A where not(A contains 'apple')",0)))
Original answer:
Criteria 1:
=COUNTUNIQUE(IFERROR(FILTER(A:A,SEARCH("apple",A:A))))
Criteria 2:
=COUNTUNIQUE(IFERROR(FILTER(A:A,ISERROR(SEARCH("apple",A:A)))))
This gives unpredictable results when referencing cells with clickable URLs in. IMO, this is a bug associated specifically with the FILTER function, and how it parses URLs. QUERY works around this because (again, IMO) it will first convert the source data to a single data type (in this case text) in each referenced column.
Sorry about the imprecise title. Allow me to elaborate. I'm currently in the process of making 'Order' sheets for the small retailer i work for. Some items are easy to count due to low inventory while other items are abundant and difficult to count but easy to gauge whether we ought to order them.
When an employee takes a store count, the on-hand number they put down is contrasted with a minimum. The minimum is our lower threshold. The minimum is subtracted by the input quantity and a formula produces a third column, "Order". If the number in the order column is < 0 then a query function on a separate sheet will copy the entire row. To be clear, there are three columns, "On Hand", "Minimum", "Order", with the "Order" column containing the following mathematical formula:
="Minimum" - "On Hand"
[Cells are specified so that it would look more like "=B2-A2".]
However, I'd also like to include the ability for employees to put a simple 'x' in the count spot, signifying that we need to order the product without having to count every single instance of the item. I'd still like to include the ability for them to enter a number if they so choose. I'd like for them to be able either the number or the 'x' in the same column. I'm currently using the following query function:
=QUERY('String(Fail)'!A:D;"select * where A contains 'x' or C > 0")
[The above is from a sheet I'm experimenting with. I will provide a link below in case you're more hands-on.]
The issue arises when the formula in the "order" column outputs any sort of number. If the formula is functional, no row marked with an 'x' is copied to the new page via the query command. If any row produces a numeric, no 'x' rows are copied over at all. I've experimented a bit but am at a loss as to where to go next.
The sheet I'm currently experimenting with is linked below. If you'd like any additional information I'd be happy to provide it. I'm relatively new to all of this so excuse my stupidity. I do recognize that I could very likely make a script for this but am not well versed in scripting with Google Apps and enjoy the immediate benefits of the query function.
Any help is welcome. Thank you.
Experimental Spreadsheet
All the values in a column need to be of the same type in order to be evaluated by QUERY. The mix of 'x' and numbers is confusing things.
If you use the Format menu to ensure all the values in column A are Plain Text, then your Query will work. (Formatting a numeric value as plain text does not stop it from working in a numeric calculation, so your column C survives.) Here's a screenshot of your query, after doing that formatting:
Based on your specification, your query needs to have the comparison to zero reversed, like this:
=QUERY('String(Fail)'!A:D;"select * where A contains 'x' or C < 0")
^^^