Combining Query and If Statements in Google Sheets - google-sheets

I need to know if this is possible:
I have a data in Google Sheets. I want to do a query on the data itself.
I want to be able to query any data that has a certain cell filled in with a date format. If the cell is filled in with a date format, then the data is transferred over to the query but if it does not contains date data in the cell, then the data won't get queried over.
So Is it possible to put a nested if statement in Query?
For example this is the workflow of the query
Check if Date cell is filled with data >> Check for the Broker name >> Select Column B and F to show in the query
Below is my Query formula so far:
=QUERY({Funded_2022!A:AM, if(Not(IsBlank(W:W)))}, "Select B, F")
and its coming with the error message:
Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 2002. Actual: 1

try:
=QUERY({Funded_2022!B:B, Funded_2022!F:F, Funded_2022!W:W},
"select Col1,Col2 where Col3 is not null", )

Related

Count data between two data ranges

I've spent countless hours trying to count this data between two date ranges. I'm using a formula I've previously used in the past, but with no luck.
(Fixed - Sample Data - see updated Actual Data below, formula is not working with actual data)
Current Formula vs. Expected Results
=Query(flatten(filter(E3:E11,D3:D11>=D16,D3:D11<=E16)), "Select Col2,count(Col2) where (Col2 is not null) group by Col2 label count(Col2)''",)
I've tried:
COUNTIFS but could not find how to include criteria.
Using INDIRECT with named range in the 'Expected Results' Reason 1 - Reason 5 Column and COUNTIFS in the column to the right.
Googling over 50+ different sites and formulas.
(Updated: Actual Data) (Error - Not working)
[Current Formula and Empty Result]
(https://i.stack.imgur.com/SnRkm.png)
The actual data is being pulled from the Data sheet. The data on this sheet looks like this
Data on the Data sheet that's pulled onto the date filter sheet
(https://i.stack.imgur.com/yZNh9.png)
and is using this formula:
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(O11:O, ","))="",,TEXT(J11:J,"MM/DD/YYYY")&"×"&L11:L&"×"&M11:M&"×"&N11:N&"×"&SPLIT(O11:O, ","))),"×"),"where Col2 is not null")))
Solution:
I used the same code I previously used. However, the dates that were being selected could not be selected with the data that was being pulled.
I used:
=INT(O3)
to copy the date into another column, dragged the formula down, and used the filter to select the date from this new column. The date filter then worked.

Google Sheet Query to pull rows with errors

I'm trying to utilize Google Sheet to pull out rows which has errors.
Below is a screenshot on how the raw data looks like (Raw Data 1):
Column A is the key, which is used in Column F to do a VLOOKUP in another tab. If not found, replace with a "-" string value, as below:
=IFERROR(VLOOKUP(A2,'Raw Data 2'!$A:$E,5,FALSE), "-")
Column G checks whether Column E = Column F.
Column H is a formula which is (F-E)/E. In this case, a "#VALUE!" error pops out due to column F, which is okay for now.
Below is my processed tab with the formula:
=QUERY('Raw Data 1'!A:J, "SELECT A,B,C,D,E,F,G,H,J WHERE F='-'")
I have also tried:
=QUERY('Raw Data 1'!A:J, "SELECT A,B,C,D,E,F,G,H,J WHERE H='#VALUE!'")
Both give me empty results. Is there a way to make the query work such that it picks up rows where the VLOOKUP in Column F fails, or when Column H returns an error?
Edit 1: I am not able to use "Filter" as my Query needs to exclude Column I.
Thanks!
Edit 2: Created a sample sheet for reference thanks to the suggestion of #player0: https://docs.google.com/spreadsheets/d/1Htj6O5VbGyRCB_X7Q0epIg8OkhrHEFYnMAH1HJckVDo/edit#gid=1568356550
Try this:
=FILTER('Raw Data 1'!A:J, 'Raw Data 1'!F:F="-")
Or:
=FILTER('Raw Data 1'!A:J, ISERROR('Raw Data 1'!H:H))
update:
=ARRAYFORMULA(QUERY(TO_TEXT('Raw Data 1'!A:J), "WHERE Col6='-'", ))

Google Sheets Query Error: Query Not Returning proper Array value when a condition is TRUE

I'm trying to solve why one of the Google Sheets I maintain is failing to operate properly. I've isolated that the issue is with a query
QUERY(Import_MJL!A:BU, "select A where AJ> 0")
For reference the Import_MJL sheet is a static database. The AJ column holds a currency value. When performing an IF function of that column, it returns as TRUE as seen here
if(Import_MJL!AJ2 > 0,1,0)
What could be the reason that the query is not recognizing when my AJ Column is above 0 ?
Screenshot for bellow reference. Row 1 holds the code & row 2 holds the Results (The B2 Cell should result in an array whose length is over 10K but only returns the header. The Import_MJL!AJ2 cell has value 38K and should be a result of the cell on B2)
Screenshot of code and results
Thanks for the time y'all!
Chances are that Import_MJL!AJ2 does not contain a number but the text string $38,738.00 that only looks like a number. Many spreadsheet functions will automatically convert such values into numbers, but query() will not.
You can check whether a value is actually a number with the isnumber() function.
Here's a quick fix to try:
=arrayformula(
query(
{ Import_MJL!A1:AI, value(Import_MJL!AJ1:AJ), Import_MJL!AK1:BU },
"select Col1 where Col36 > 0",
1
)
)

Import selected rows with query on importrange

I'm trying to import select rows from a Google spreadsheet based on the value of a single cell in each row.
As such, I'm using the following:
=query(IMPORTRANGE("KEY","Form Responses 1!A:L"), "select * where J contains 'DENIED' ")
Wherein the KEY is an actual spreadsheet Key. I tested the importrange part, that is without the query, to confirm it works. It does. Furthermore, within the Google Spreadsheet itself I can query the sheet and get it to work.
The error I receive is:
#VALUE Error Unable to parse query string for query parameter 2: NO_COLUMN_J
(There is a column J.)
When you use an importrange as a dataset, you need to refer to the columns by number rather than letter. The formula also works without 'select *'. Try:
=query(IMPORTRANGE("KEY","Form Responses 1!A:L"),"where Col10 contains 'DENIED'")

Google sheets conditional formatting based on =QUERY result

I am trying to conditionally format a row in Google Sheets based on the result of a QUERY operation. I can get the QUERY to return the value I want (either 0 or non-zero), however QUERY insists on returning a header row.
Since the QUERY now takes up 2 rows for every row of data, changing the format of the row based off the QUERY result starts to get weird after just a few rows.
The problem I am ultimately trying to solve in the case where I enter a list of names, and I want to compare each name to a list of "NSF Names". If a name is entered, and it exists on the NSF list, I would like to flag the entry by highlighting the row red.
Help is greatly appreciated.
Edit: Formula, as requested:
=query(A:D,"select count(A) where C contains '"&E1&"' and D contains '"&E2&"'")
A:D is the data set (A is a numeric ID, B is full name, C and D are first and last names respectively).
E1 and E2 are placeholders for the person's first and last name, but would eventually be replaced with parsing the person's name, as it's inputted on the sheet (TRIM(LEFT(" ", A2) etc...)
I can get the QUERY to return the value I want (either 0 or non-zero),
however QUERY insists on returning a header row.
There might be better ways to achieve what you want to do, but in answer to this quote:
=QUERY(A:D,"select count(A) where C contains '"&E1&"' and D contains '"&E2&"' label count(A) ''")
A query seems a long-winded approach (=countifs(C1:C7,E$1,D1:D7,E$2) might be adequate) but the label might be trimmed off it by wrapping the query in:
index(...,2)

Resources