So I am using a combination of query() and importdata() to pull data from another file. A simplified version of the results I get are the columns Supplier and Week where Week would be of the form WK01, WK11, WK43 etc.
How can I filter the Week column so that I only get weeks which have a week below WK10 in my results? In normal SQL you could just do something like where right(Week,2)<10 and this would return only results where the Week would be below WK10 but not sure how to do such a substring filter in Google Sheets' Query function.
you can use regex like:
where Col2 matches 'WK0[1-9]'
or:
where Col2 matches 'WK0.'
Related
I have a list of email addresses in one sheet (first column).
I have a list of transactions in another sheet with emails and sale amounts.
I am looking for a formula that adds up all the transaction $ sales for any transactions made by the people (emails) in the first sheet.
Any help would be much appreciated!
Your sample data is very limited (only one row matching one person, in fact). But the following formula should work for you. Place it in a new sheet, in cell A1:
=ArrayFormula(IFERROR({"Name","Total"; QUERY(FILTER(Transactions!A2:D,NOT(ISERROR(VLOOKUP(Transactions!A2:A,Tags!A:A,1,FALSE)))),"Select Col2, SUM(Col4) GROUP BY Col2 ORDER BY Col2 LABEL SUM(Col4) '' ")},"No Data"))
This one formula will produce the headers (which you can change within the formula itself as desired) and all results.
FILTER filters in only 'Transactions' data (names through amounts) where the emails are found in the 'Tags' sheet.
Then QUERY returns the name and totals for each match in alphabetical order by name.
If there are no matches, "No Data" will show instead.
If I understood your question correctly!
Try this on the sheet, where you only have emails and wanted to get sum of sales amount
=sumifs(range_whichHasTransaction , range_of_Email_inThat_TransactionsTable , Cell_Reference_ofEmail_forWhich_you_want_sum_the_Transaction_Amount)
it will Look something like this:-
sumifs(TransactionSheet!B:B,TransactionSheet!A:A,Emails!A2)
Reference
SUMIFS
How to take the current month number in the Select query in google sheets?
I am writing a query like this wherein Col21 I have month numbers like 1,2,3 4, etc based on month
=QUERY({Sheet1!A:X},"Select Col7,Col13 where Col21= '&month(today())&' ")
It is giving me headers only
whereas when I am writing a query like this :
=QUERY({Sheet1!A:X},"Select Col7,Col13 where Col21 contains '8' ")
It is giving me all records, but I want to replace the static value of month by Current month number only; what should I do for this so that when month changes I don't have to do any changes in the query.
Please make sure Col21 is in number, not in string
=QUERY({Sheet1!A:X},"Select Col7,Col13 where Col21= "&month(today()))
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.
I have a Google Sheet with some stock information.
I'm using the formula GOOGLEFINANCE($B2, "price",TODAY()-15) to retrieve historical information about a stock (symbol named in $B2).
That returns a 2x2 table:
Date Close
8/25/2017 17:36:00 7.46
I only want the 7.46:
Using =FILTER(GOOGLEFINANCE($B2, "price",TODAY()-15),{FALSE; TRUE}) I get:
8/25/2017 17:36:00 7.46
I can't see to be able to nest FILTER twice.
I checked the documentation. Other than say that I should not use FILTER to filter columns and rows in the same call, I didn't get much out of it.
I gather a lot of stock information and always use index to get the stock price.
=index(GOOGLEFINANCE($B2, "price",TODAY()-15),2,2)
If you want the date use this. Be sure to format the cell as date or date/time.
=index(GOOGLEFINANCE($B2, "price",TODAY()-15),2,1)
For 2 filters try:
=FILTER(FILTER(GOOGLEFINANCE($B2, "price",TODAY()-15),{false;true}),{false,true})
I prefer query in this case:
=QUERY(GOOGLEFINANCE($B2, "price",TODAY()-15),"select Col2 label Col2 ''")
Also please try this formulas separately:
={false;true}
={false,true}
and see the result.
I have a Google form and a spreadsheet that is supposed to process it. The spreadsheet needs to filter the responses by date and get their respective data after that.
E.g. Consider:
With the columns being A and B and the rows being 1-4.
How do I filter it by month in ascending order followed by adding the amount next to it?
So it would look something like:
I understand how to filter by month in ascending order. It is done using =SORT(FILTER(A:A, MONTH(A:A)=1)) (for Jan). But how do you get the data next to it? I have tried =INDIRECT(ADDRESS(SORT(FILTER(A:A, MONTH(A:A)=1)), 2)) but there is no error and it is blank.
You can do SORT for whole A:B instead of doing only for A:A.
Eg:
SORT(FILTER(A:B, MONTH(A:A)=1),1,TRUE) for Jan
SORT(FILTER(A:B, MONTH(A:A)=2),1,TRUE) for Feb
Please refer link here and see whether this is what you expect.
try this:
=QUERY(A:B,"select month(A), A, sum(B) where not A is null group by month(A), A")
or this:
=QUERY(A:B,"select day(A), sum(B) where not A is null group by day(A) pivot month(A)")
or you could use your formula =SORT(FILTER(A:A, MONTH(A:A)=1)) twice and use custom date format for first column to label it as JAN, FEB...