wrong result with google sheet get sheet from another URL with condition - google-sheets

what wrong with this command
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/XXXurlXXX/edit#gid=0","sheet1!A:Z"),"select Col2 WHERE Col6 contains 'main' ")
the results start from second row or first or third , there is no rule for this
i need to start from first to end
i try with wrong condition like contains 'main 111' , then i get first three results in one row
main sheet
result sheet

=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/XXXurlXXX/edit#gid=0","sheet1!A:Z"),"select Col2 WHERE Col6 contains 'main'", 1)
Note the (optional) headers argument at the end of the query.
See if that works?

Related

Extract Value from Cell on Another Sheet Based on List

I have a list of data on one sheet. A second sheet is used to display who's done what, like a dashboard. I've been given an array formula to generate the data that looks up the employee's name, and displays it if they are present on the list for a course completed. If so, a "yes" is listed on the dashboard under the corresponding course number. I cannot figure out what I need to change the REGEXREPLACE with to present the date column from the data list instead of "yes". I'm aware REGEXREPLACE only works for text values, and dates aren't - even changing the date column to text seems to matter not.
Here is a working example of the current array formula:
https://docs.google.com/spreadsheets/d/1jkG515zyl4UxRHxhtFTjgWsjG0aBE4vsOxbpvqgjogU/edit#gid=536376041
Here is the formula used:
=ARRAYFORMULA(IF(A5:A="",,REGEXREPLACE(IFNA(VLOOKUP(A5:A,
QUERY({TRIM('Form Responses 1'!B2:G)}, "select Col1,count(Col1) group by Col1 pivot Col6"), MATCH(F2:P2,
QUERY(QUERY({TRIM('Form Responses 1'!B2:G)}, "select Col1,count(Col1) group by Col1 pivot Col6"), "limit 0", 1), 0), 0))&"", "\d+", "yes")))
In the above example, I need the Date Completed from col D on the Form Responses sheet.
Here is a first attempt that might help you.
This is a straightforward query, that pulls the dates, and pivots to have the employee names on the left, and the course names on the top.
But it doesn't try to match up data with an existing list of employees - it just lists all of the employees that have submitted a form. So if you want to see all employees, with blank rows for those who haven't submitted a form, this won't work for you.
The formula, in A2,is:
=ARRAYFORMULA(QUERY({'Form Responses 1'!B2:G}, "select Col1,max(Col3) where Col1<>'' group by Col1 pivot Col6 order by Col1"))
See tab Sheet1-GK, added to your sample sheet.
Let me know if this helps, or if you need something different.
UPDATE:
To limit the result to a specific list of courses, use the following modification:
=ARRAYFORMULA(QUERY({'Form Responses 1'!B2:G},
"select Col1,max(Col3) where Col1<>''
and Col6 matches '" & TEXTJOIN("|",1,F2:2) & "'
group by Col1 pivot Col6 order by Col1 "))
Here, the list of desired courses to report on is in F2:2, where you had them originally, but this list could be kept anywhere, even on another tab. If you name the range where you place it, that can simplify this formula a bit. For now, you could just hide row 2. I've grouped it, on the left, to hide it. Use the [+] to reveal it again.

Query Importrange Issue

I am not sure why this functionality stopped working, but I am sure it has to do with inconsistent back end data or how the query condition "CONTAINS" needs to be changed. The IMPORTRANGE portion works just fine, but will not always pull data into the front end sheet. The query portion looks like this
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS "&'Job Number'!A1&" ORDER BY Col3 ASC,1
Column 2 contains job numbers that are xxxxx with another 3 digit code appended to end of it. It will only populate temporarily if I manually go into the sheet and edit the IMPORTRANGE range values. If I close the spreadsheet and open it again it will not populate. Does the data in Column 2 need to be a consistent datatype throughout the column or it will break the query?
Unfortunately we do not have a test sheet, so we can not know what the expected results would be.
Nevertheless, your formula syntax is not correct.
The correct syntax would be:
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS '"&"JOB"&A1&"' ORDER BY Col3 ASC,1
Please notice the syntax '"&"JOB"&A1&"'
(If you still have issues please share a test sheet and let us know.)

Using =averageifs with multiple text criteria in different columns

I'm busy with creating an spreadsheet where I can get the average price of holidaydeals with a specific tag (f.e. a destination). When I do this for only one tag column the formula is working :) :
=averageifs(C4:C10,E4:E10,L1,F4:F10,"Frankrijk vakantie")
But... I have more then 10 tag columns in total and in every column something like "Frankrijk vakantie" could be found. My simple mind thought, okay lets change F4:F10 (in this example) to F4:G10 to look for "Frankrijk vakantie" in two columns. But... the formula didn't work.
Link to spreadsheet: https://drive.google.com/file/d/1Gw5VC5qT1bzbFIPBu5j4dLXBmJjh7GuW/view?usp=sharing
I've also added a screenshot. I hope that someone can help me with this. Would be great, thank you!
In L2 try
=query({C4:C11, ArrayFormula(N(mmult(N(F4:O11="Frankrijk vakantie"), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
and see if that works?
EDIT: to include a month/year filter try
=query({C4:C11, ArrayFormula(N(mmult(N( (F4:O11="Frankrijk vakantie")*(E4:E11=L1)), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
The formula makes use of a virtual array, containing the values of column C and the output of the mmult() function. The latter creates a column with 1's if 'Franrkijk vakantie' is found in that row AND the date in column E matches the date in L1. The query then averages the values from column C and filters out the rows where the conditions of the MMULT() are not met.
EDIT 2: To check for a 'double match' in the row, try
=query({C4:E11, transpose(query(transpose(F4:S11),,9^99))}, "Select AVG(Col1) where Col3='"&L1&"' and Col4 contains 'Frankrijk vakantie' and Col4 contains 'Europa vakantie' label AVG(Col1)''", 0)
Change range to suit.

Google Sheets Query Select is making an extra empty row

Both of these are reading right so I have the link and the sheet and all the info correct, it's just outputting a little strange. I believe it's the same issue on both of them. Any help much appreciated.
1st issue:
=query(importrange("link","b9:d1000"),"Select Col3 where Col1 = '"&C4&"' ")
When I do this one it needs two rows. It puts the value I want in the first one and leaves the second row blank. As in, if I put anything in the second row, it gives me #REF can't overwrite that cell.
2nd issue:
=query(importrange("link","b9:d1000"),"Select max(Col3) where Col1 = '"&C4&"' ")
When I do this one It gives me two rows: the word "max" and then below it the actual max value. How do I get it to give me just the max value
These are different issues. In the first, there happen to be two rows that meet the condition in where; the second of them has empty Col3. If you want only one result, either revise the where condition by adding some additional requirement, or put limit 1 at the end of query string, to make sure only one row is returned.
"Select Col3 where Col1 = '"&C4&"' limit 1"
Second issue: "max" is the name given to the output column. This name can be changed to empty string with label max(Col3) '', which will eliminate the cell with the name.
"Select max(Col3) where Col1 = '"&C4&"' label max(Col3) ''"

Google SpreadSheet Query: Can I remove column header?

I'm doing this query at my google spreadsheet:
=QUERY(H4:L35;"select sum(L) where H='First Week'"; -1)
But it returns a little table with "sum" as header and result below it. What I want is just the result! How I remove header? Can I?
Try this:
=QUERY(H4:L35,"select sum(L) where H='First Week' label sum(L) ''")
=QUERY(QUERY(A1:D, "SELECT *", 1), "SELECT * OFFSET 1", 0)
The outer query: "SELECT * OFFSET 1" excludes the first row (the header).
The inner query explicitly specifies one row of headers (via the third argument supplied to QUERY), whilst the outer query specifies none.
=INDEX(QUERY(H4:L35;"select sum(L) where H='First Week'"; -1),2,1)
This just parses the returned array and selects the 2nd record returned in the first column.
You can also do this with the filter function which is less compute intensive.
=SUM(FILTER(L4:L35, H4:H35 = "First Week"))
I have a QUERY which is returning the top 3. I could not get this to work when returning multiple rows. I ended up just hiding the row with the formula and only the answers show now.
For queries using pivot, try using INDEX to remove headers from the pivoted columns.
=INDEX(QUERY('Class hours'!A2:C11,
"select sum(C)
where A = '"&A5&"'
group by A
pivot B"), 2)
Got the answer from this thread:
https://stackoverflow.com/a/63468791/5424088
... or this
=QUERY(QUERY(H4:L35;"select sum(L) where H='First Week'"),"OFFSET 1",0)
This is more concise when ALL label classes are not wanted.
Note that 'select' and 'where' classes are not required in the second QUERY statement.
Instead of labeling column names as blanks using '', you can omit all headers like this:
=QUERY(H4:L35,"select sum(L) where H='First Week'", 0)
See the format here.
Example:
=QUERY(B4:C38,
"SELECT C, sum(B) where C!='' group by C label C 'Member', sum(B) 'Sum'"
)

Resources