Making a query formula search box with partial match - google-sheets

Thanks in advance to all,
I have a spreadsheet with multiple sheets. I want my master sheets to have a search box based on a query that is referencing from a cell( my case A1)
*iv managed to accomplish this, but the search results are only exact match.
can someone help please how can make it a partial match instead of exact or even combined the two.
**iv tried this thread but it doesn't work, maybe I'm doing something wrong
thanks:
Exact result in Google Query, followed by partial match if exact result does not exist
this is the query that is working right now
=QUERY({sheet1!A2:I24;'sheet2'!A2:I26;'sheet3'!A2:I26},"select Col1, Col2, Col4,Col7,Col9 where Col1 = '"&A1&"'",1)
Cheers to all,

From the reference:
like - A text search that supports two wildcards: %, which matches
zero or more characters of any kind, and _ (underscore), which matches
any one character. This is similar to the SQL LIKE operator. Example:
where name like fre% matches 'fre', 'fred', and 'freddy'
where Col1 like '%"&A1&"%'"
Another, more powerful approach is to use filter + regexmatch:
=filter({sheet1!A2:I24;'sheet2'!A2:I26;'sheet3'!A2:I26},
regexmatch({sheet1!A2:A24;'sheet2'!A2:A26;'sheet3'!A2:A26}, A1))
See more on regex syntax here.
The result of a filter may be a query data source:
=query(filter(..., ...), "select Col1, ...")

Related

In Google Sheet, how do you use SUMIFS with OR logic matching a list of items?

In order to clarify the scenario, please check the example here:
https://docs.google.com/spreadsheets/d/1E_xyPvkTIObG5JA4UfG1EQa74cFEc9QiznidJ4HSmEY/edit?usp=sharing
What I want to do here is to:
filter by date (matching a certain date)
filter by product id (matching a list of specified ids)
sum up the total
I did try to find some ideas, though none of them worked, including the solution in the article below
https://exceljet.net/formula/sumifs-with-multiple-criteria-and-or-logic
Really appriciate if someone could point me in the right direction, thanks!
use:
=QUERY({'raw data'!A2:C},
"select Col1,sum(Col3)
where Col2 matches '"&TEXTJOIN("|", 1, 'ids to match'!A2:A)&"'
group by Col1
order by Col1 desc
label sum(Col3)''")
Sumifs is different than Sumif. You also have some text mixed with numbers. Your dates are text while Column b is numeric. Try this:
=Sumifs(C:C:,A:A,"2022-09-08",B:B,82267,B:B,82602) +
Sumifs(C:C:,A:A,"2022-09-08",B:B,82267,B:B,82602B:B,82604)
As Player() points out, if you have too many products to include, using sumifs would get pretty tedious and you ought to consider using a different function (i'd use filter). However since your question was Sumifs related, that's your answer.
To illustrate how this would work with something Filter, you could do this:
=sum(filter('raw data'!C:C,('raw data'!A:A=A2)*
(isnumber(match('raw data'!B:B,'ids to match'!A:A,0)))))

How to extract text from cells with distinct

I tried different approaches to accomplish what I am looking for and it might not be possible with how I have formated my data but I will try to explain it to see if there is a way.
My origin of data looks like the following:
Case
HELP
100
HELP-01
HELP-02
101
HELP-01
102
103
HELP-03
What I want is to be able to extract the HELP-* into another column without duplicate values and one after another. The result I am looking for is from the above table been able to have this:
HELP
HELP-01
HELP-02
HELP-03
Is there a way to do this in Google Sheets?
Thank you,
Alternatively you can use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 like 'HELP-%'"))
The QUERY() will now only return those values that start with 'HELP-' in the case you might have other string-values.
A littel more specific even, could be to use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 matches 'HELP-\d+'"))
Where 'matches' will now use the regular expression to only return values that start with 'HELP-' but end with any 1+ digits.
Try this in Google Sheets
=sort(array_constrain(unique(flatten(B2:C)),counta(B2:C),1))

How to concatenate strings and select the same columns multiple times using Query (Google Sheets)

I am trying to generate a table for the Gantt chart. Table should have this format:
https://developers.google.com/chart/interactive/docs/gallery/ganttchart#data-format
So,I need task name the same like taks ID, but in Query I can't use Col1 twice (I get error)
=QUERY({Tab1;Tab1};"select Col1,Col1,Col5,Col16,Col17 WHERE Col16>now() ORDER BY Col5 DESC,Col17 ";0)
The second point is that it is also not possible to merge two columns as a result, so it doesn't work:
=QUERY({Tab1;Tab1};"select Col1+Col7,Col1,Col5,Col16,Col17 WHERE Col16>now() ORDER BY Col5 DESC,Col17 ";0)
Here is my data and 2 results what I neet to get by QUERY
https://docs.google.com/spreadsheets/d/1CZYgfYo6oIeONZOH6ZR5rOW615HuH4ICaoe7lj0dapw/edit#gid=0
These are such trivial things in a real SQL, is there no way to do it somehow straightforwardly in Google Query? So far I have found a combination of QUERY and ARRAYFORMULA but then there are very complicated queries - mutants. Not easier?
You don't need Query, just Arrays.
You will get the first result from this code:
={ARRAYFORMULA(B3:B&" "&C3:C)\A3:A}
The second result from this code:
={A3:A\A3:A\B3:B1}
Based on your example I assume that you are not using US spreadsheet settings.
If so formulas have to be change to:
First:
={ARRAYFORMULA(B3:B&" "&C3:C),A3:A}
Second:
={A3:A,A3:A,B3:B}
Link to working example: https://docs.google.com/spreadsheets/d/1eMkOkyFwvDeYSy-8UlhQum4OWcb-4WJqGxy_CXM8pVs/edit?usp=sharing
I see that in your real sheet you would like to compare some data with now(). You can easily do this using array I propose as a source to Query. There will you have something like this (of course now it will not work - its only an example - an array have only 2 columns, not 15):
=QUERY({ARRAYFORMULA(B3:B10&" "&C3:C10)\A3:A10};"select * where Col15>now()";0)
About Query - you can't perform arthmetic operations on column containing strings. Look at the documentation: https://developers.google.com/chart/interactive/docs/querylanguage#arithmetic-operators
"I can't use Col1 twice (I get error)"
You can duplicate your indata that to solve this.
QUERY({Tab1 Column 1\Tab1 Column 1};"Select Col1, Col2......"
"Tab1 Column 1" is now Col1 and Col2
"The second point is that it is also not possible to merge two columns as a result, so it doesn't work:"
Yes, adding result of column is possible "select Col1+Col7......" is correct.

How to refer to column 'BY' in query?

In my Google spreadsheet, i'm using the query function to get data from one sheet onto another. The query looks something like this:
=QUERY('mySheet'!$A$1:100,"select F where "&C$3&"='myValue'")
This works fine until cell C3 has value "BY" (because the word "by" has significance in the query language). I've tried using single quotes, but then the query uses header "BY" instead of column BY and it returns an empty result.
Any ideas on how to work around this?
Put it in backticks.
=sum(QUERY(select `BY` where `BY` is not null limit 7))
This will sum the first 7 values in column BY.
(This was fun to debug. The formula worked in every other column...)
"BY" is a special word. It is present in clause group by
You may use this:
=QUERY({'mySheet'!$A$1:100},"select Col5 where Col"&C$3&"='myValue'", 0)
and paste the column number into C$3
see more info here
BTW you may use function column() to know BY is column 77 or find the right number by header name: =match("column name", 'mySheet'!1:1, 0)

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