IMPORTRANGE: value missing? - google-sheets

I have been working on this issue for a few weeks now and can't seem to find a solution. I used this answer (IMPORTRANGE with CONDITIONS) to get as far as I could, but I keep getting a value error.
This is the sheet I'm working with.
My goal is to use the first tab in the sheet (All Games) to enter all the games that I come across to create a compendium. But, then I want it to automatically populate the other tabs based on certain criteria (what type of game, skills learned, etc.)
On the Warm-Ups tab you'll see the formulas I have tried. A1 is the most recent.
Here is the formula I tried:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag/edit#gid=1359689553", "All Games!A1:A1300"),"SELECT Col1 WHERE (Col2 = 'w') ")
I am getting a value error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Col2

you are trying to reference Col2 but you selected range A1:A1300 which is just 1 column. therefore try:
=QUERY(IMPORTRANGE("1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag", "All Games!A1:B1300"),
"SELECT Col1 WHERE (Col2 = 'w') ")
from the brief look on your sheet, you may want use matches or contains instead of = in your QUERY

You are only importing (part of) ColumnA - so no wonder Google can't find a second column :)

Related

Import Range Query not importing data

Sorry I know this question has been asked before - I have tried changing my query around but can't seem to get it to work as expected, doesn't look to be anything wrong..
I am simply trying to query data from one large master sheet into a few separate sheets. I am using importrange to get the data from sheet, and a simple select query to filter by one of the columns. If I do a select * I get all the data as expected, but can't use a WHERE clause with any column (I just need 1 of the columns, but I tried with a few different ones).
Appreciate any help!
Query:
=QUERY(IMPORTRANGE("1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk","Sheet1!B:I"),"select * WHERE 'Rank'='LTC' ")
Columns
Username Rank Time In Service TIS Time In Grade TIG Promotable Awards PLT/SQD
Source sheet: https://docs.google.com/spreadsheets/d/1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk
Test sheet: https://docs.google.com/spreadsheets/d/1UCucsfE0M4j95d_47iN0LrAhS0luv8wXVMHRVTHJHRQ
As player0 stated, you should refer to the columns by its number, you can select multiple columns and state multiple "where" statements by using Col1,Col2, etc respectively. In this case: Where Col2 = 'LTZ'
try:
=QUERY({IMPORTRANGE("1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk", "Sheet1!B:I")},
"where Col1='LTC' ", )

How to 'count' only when header matches value?

I have a Google Form that collects a bunch of data from dropdown questions on a Sheet with each question going to one column (as normal). On separate sheets, I want to be able to count how many times each option is selected.
Here is an example of what the response sheet might look like. A, B, and C are all questions.
I would then have separate sheets for 'Person?', 'Place?', and 'Thing?'. The 'Person?' sheet would look something like this:
I want to be able to add in the count of each time the option appears for that question. In the example, notice that 'Napoleon" is in both Col A and Col C. If I just count the number of times 'Napoleon' appears, I will get '2' even though he only appears once in the "Person?" responses.
I originally used a QUERY function like =QUERY('Input Data'!1:1000, "select count(A) where A contains '"&$A2&"'",0). BUT, I need it to be dynamic. So the "Person?" question may not always be Col A. I want the Query (or whatever formula) to search the headers and only return the count of that option for that question even if the column location changes.
Okay, I figured it out! In case someone else is curious, I used this formula:
=QUERY({'Input Data'!A1:L}, "SELECT COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") WHERE Col"&MATCH("Person?", 'Input Data'!1:1,0)&" CONTAINS '"&$A2&"' label COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") ''",0)
Lee, I sent you a PM about your most recent post, but in the process, I came across this one. There is no need for multiple formulas or manual entry references. One formula can produce the entire report with headers, listing and counts:
=IFERROR(QUERY(FILTER(FILTER(A:L,A:A<>""),A1:L1="Person?"),"Select Col1, COUNT(Col1) GROUP BY Col1 ORDER BY Col1 LABEL COUNT(Col1) 'Count'",1),"No Matches")
Just fill in the header your looking for between the quotes where Person? is now.
The double FILTERs mean "Start with only rows where Col A is not null and Row 1 reads 'Person?'"
Then QUERY simply returns the unique names in the left column and their counts in the right column. Because the QUERY had a final parameter of 1, any existing header will be kept (in this case, the one you were searching for); and the created column will receive a header (i.e., LABEL) of Count.
IFERROR will give a friendly error message if no matches are found (in which case check that what you entered for the search in the formula exactly matches a column header in the range).

Only apply complex arrayformula() to rows with certain value in dataset

I have a quite complext formula (i mean that is complex to me) that Tom Sharpe helped me building to aggregate values and ordering them by months in a row(you can find the details in the original post but i think you'll only need the final formula which is:
=ArrayFormula(mmult(sequence(1,counta(A2:A),1,0), if((C2:index(C:C,counta(C:C))<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:index(D:D,counta(D:D))>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:index(E:E,counta(E:E)),0)))
and here is the result -> [J1:U1]
Now, what i would need to do as the final step is to be able to group data by a certain label (John or Jane in the example) on separate rows, but mantaining the order/aggregate by month on the row. On the example, this would mean having one row with only 'John' data and below, one with 'Jane' values.
I am struggling to understand how to adapt the formula to do so.
I have tried:
Using another array to first return a list of these labels with query(unique()) or something like that, but then i struggle looping in it with the other formula.
A bit more simplistic but it could work after all: on the 1st row (the cell next to where the data will be returned) writing 'John', on row 2 'Jane' and then using filter() to only pull data that matches. The 'John, Jane' value is for the example but the real labels won't be that many, the list of labels don't need to be dynamic.
The thing with these solutions is that they work when used separately, but i can't figure out how to nest this in the first arrayformula() that Tom helped me with...As i am just beginning with the google sheets queries.
I don't really need necessarily the complete formula/code but maybe just directions or tips to visualize the way i could solve this.
Thanks to all who might contribute
With hindsight I might have done better to go down the route of using a query to calculate the sums on my previous answer rather than Mmult.
This uses the same method as before to create a 2d array of amounts vs dates (going across) and individuals (going down). Then it uses Textjoin to generate a query to group by name with the required number of columns.
=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1"))
This is the generated query
select Col1,sum(Col2),sum(Col3),sum(Col4),sum(Col5),sum(Col6),sum(Col7),sum(Col8),sum(Col9),sum(Col10),sum(Col11),sum(Col12),sum(Col13) where Col1 is not null group by Col1
Ideally there should be an extra section saying label sum(Col2) '' etc. to suppress the 'Sum' headers.
=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1 label sum(Col" & textjoin(") '', sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2)) & ") ''"))

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 do I do a date-based query in new Google Spreadsheets?

I am using the new Google Spreadsheets that was rolled out a couple of weeks back. I'm using a following query to pull data out of another spreadsheet:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!A:D"), "select SUM(Col4) where ( Col1 >= date '2012-1-1' ) ")
The query works perfectly well if I remove the bit 'where ( Col1 >= date '2012-1-1' )'. It will pull data and sum it correctly.
But what's wrong with my where-col1-date filter thingy? It's written the way it was in previous version of Google Spreadsheet, and it gives no error messages. It just returns a header and no result, as if it didn't find a single date. The dates in the data file are in column 1, written in format 4/7/2014, for example. This used to work in the previous version and I'm at a loss now.
I have several suggestions here. But first: Let's copy the "2012-1-1" value to a particular cell, say F5, and write it with the exact same date format az in the original spreadsheet: 1/1/2012.
Use FILTER function:
=SUM(FILTER(IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!D:D"), IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!A:A")>=F5))
I admit that it's not that pretty because of the two ImportRange functions, but it works for sure, I tried it.
If you insist on using QUERY then try to replace the where condition as follows:
"select SUM(Col4) where ( Col1 >= " & F5 & ")"
I haven't tried this one, but the first one (with FILTER) should work.

Resources