Exclude Header QUERY - google-sheets

I want to construct a Query that takes data from multiple sheets and lists the contents of them all. All sheets have the same variables and should, therefore, be combined. When typing in 0 as the last argument of the query I always receive an error.
I am using the following formula and have tried to input 0 as well as FALSE as the last argument. Every time I received an error. In addition to this, I tried including label AI '' at the end of the statement which worked but I could not seem to also have a blank for AJ. Furthermore, I suspect that the blank spaces will still be shown which I don't want.
={QUERY(PRIO!A:AX, "select D, E where B matches 'Negative' order by D");
QUERY(collated!A:AJ, "select AI, AJ where AG matches 'Negative' order by AJ")}

not sure what went wrong because you didn't provide a copy of your sheet but try:
={QUERY(PRIO!A1:AX, "select D, E where B matches 'Negative' order by D", 1);
QUERY(collated!A2:AJ, "select AI, AJ where AG matches 'Negative' order by AJ", 0)}

Related

Google Sheets: Find a Row that Matches Only a Few Specific Characteristics

I can't seem to find the right equation to find a cell from a row that matches only a few specific characteristics. In this example, I am trying to find the equation for Column D which would be the cell in A that has the same cells for B & C.
Hope this makes sense!
I'll provide two options.
If you're sure your data will only ever have zero or one match, you can place the following formula into D2 of an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,SUBSTITUTE(VLOOKUP(B2:B&C2:C,{B2:B&C2:C,A2:A},2,FALSE)&VLOOKUP(B2:B&C2:C,SORT({B2:B&C2:C,A2:A,ROW(A2:A)},3,0),2,FALSE),A2:A,"")))
However, if you think more than one match may turn up and you want "None" to be returned if there is no match, you can use the following formula in D2 or an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,REGEXREPLACE(REGEXEXTRACT(REGEXREPLACE(SUBSTITUTE(VLOOKUP(B2:B&C2:C,TRIM(SPLIT(FLATTEN(QUERY(QUERY({B2:B&C2:C&"~",A2:A&","}, "Select MAX(Col2) where Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1"),, 9^9)),"~")),2,FALSE),A2:A,""),"^[,\s]+$","None"),"([^,\s].+[^,\s])[,\s]*$"),"[,\s]+",", ")))
The second formula will work even if there will only ever be zero or one match; it's just not necessary to have it be that lengthy. And the second formula is only as lengthy because it was unclear from your posted examples whether the data in Col A, B and C will really only ever be one word or not; so the formula is built to assume there will not always be one-word strings in those columns.
Either formula will provide results for the entire column without dragging.
Here's an option, You can use this formula in column D2:
=iferror(textjoin(", ",true,query($A$2:$C,"Select A where A is not null and A != '"&$A2&"' and B = '"&$B2&"' and C = '"&$C2&"'",0)),"None")
Limitation:
You need to manually drag the formula to its succeeding rows. Arrayformula() cannot be used in looping the query string values.
What it does?
Using query(), filter the data from A2:C that has the same current row last name(Column B) and food(Column C) at the same time having a different first name(Column A)
If there are multiple results, use textjoin() to combine them with ", " as its delimiter.
If there is no matched found, it will return an error, hence use iferror() to set the default value to "None"
Output

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

Google Sheets QUERY statement: order by average

I have this Google Sheet with a query formula in it. I am trying to use the query to display an average 1-5 satisfaction rating for each program. This script I adapted from Info Inspired - see "formula 1" - is basically working using the following formula in cell A2:
=query(ArrayFormula('Form Responses 1'!B2:E),"Select B,Avg (E) group by B label Avg(E)''")
However, this is displaying the results ordered alphabetically by program.
How can I order the output by the average rating currently in column B of the image?
I tried using the order by clause as in:
=query(ArrayFormula('Form Responses 1'!B2:F),"Select B,Avg (F) group by B label Avg(F)'' order by Avg(F)")
and
=query(ArrayFormula('Form Responses 1'!B2:F),"Select B,Avg (F) group by B label Avg(F) order by Avg(F)''")
but both gave me:
Error Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "order" "order "" at line 1, column 44. Was expecting one of: "format" ... "options" ... "," ...
I am not sure what the '' is doing, but the first query mentioned only works with it in there.
try it like this:
=QUERY(QUERY(ARRAYFORMULA('Form Responses 1'!B2:E),
"select B,Avg(E) group by B label Avg(E)''", 0), "order by Col2 asc", 0)
'' is literally nothing eg. empty label

IF statement inside QUERY in Google Sheets

I have a google sheet where I have several projects listed.
With a QUERY function I am retrieving information into another sheet for reporting purposes.
The formula I am using is:
=QUERY($A$2:$D$8,"IF(OR($C2=1,$C2=2,$C2=3), Select A, B, D, Select A, B, C)",0)
What I am struggling to do is placing an IF statement inside the QUERY function.
I would like to get the Date 2 (Col4) value if the Status (Col2) value is "1", "2" or "3". Otherwise, if the Status (Col2) value is "4", "5" or "6" I would like the Query to return the Date 1 (Col3)
Any help would be appreiated.
Thanks!
The formula would be like this:
=ArrayFormula(query({A2:B8,if(B2:B8<=3,D2:D8,C2:C8)},"select *"))
But the query isn't actually doing anything.
So you could just use:
=ArrayFormula({A2:B8,if(B2:B8<=3,D2:D8,C2:C8)})
So it is possible to include an IF statement into a query. The main thing to remember is that the query is text, so you have to end the quotations include your reference, and then restart the quotations. It's just like creating a sentence via formula. For an example, you would add the following text for a secondary condition:
"&if(T3="",""," and H = '"&T3&"'")&"
I wanted the ability to narrow down the results conditionally. So if I have a value in T3, then the condition for column H is added into my query. Otherwise, it is left out.
In case I messed something up or am not making sense, here's my actual complete formula. I also have the query using filters that reside in Q3,R3, and S3.
=query(Transactions!B1:H, "select B,C,D,E,F,G where B > date '"&TEXT(DATEVALUE(Q3),"yyyy-mm-dd")&"' and B <= date '"&TEXT(DATEVALUE(R3),"yyyy-mm-dd")&"' and D = '"&S3&"'"&if(T3="",""," and H = '"&T3&"'")&" order by B desc limit 50",1)

Conditional formatting with QUERY result in Google Spreadsheet

I have a spreadsheet with 1 sheet of software version an another sheet of installation records. I want to do a conditional formatting that compares the version of in installation (on column F) to its know latest version number on another sheet ('Software Versions').
Current Solution
I came up with this formular initially:
=AND(F2<>"", F2=G2)
It works. But I need to maintain a column of QUERY results on G2:
=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1")
Problem
Now I want to remove the G2 row altogether. I came up with this combined query:
=AND(F2<>"", F2=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1"))
But I cannot save it because it is an "Invalid Formula":
Any way to actually do it?
Try use this formula:
=AND(F2<>"", F2=IFERROR(QUERY(INDIRECT("'Software Versions'!$A$1:$B$8"),
"Select B where A='" &D4& "' LIMIT 1 label B ''"),""))
I was able to make conditional formatting with this formula.
Improvements
Use indirect to address another sheet
Use label B '' to prevent header appear as query result
Use iferror(..., "") to be sure no error occurs when no data is found with query
I'm used to the good old VLOOKUP function for my conditional formattings.
The syntax is VLOOKUP(valueOrCell, sourceRange, index, FALSE)
So if the value from first parameter valueOrCell, exists in the sourceRange, return the value at index. FALSE is to have the exact match.
In my example I'm using only a single worksheet, but if you set the sourceRange to different worksheet it works as well.

Resources