Display all values in columns (Query formule) - google-sheets

I'm trying to use a query function in my google sheet.
But I have a little problem :
When I have same/less "R" than date so it display me only date and not the "R"
For example:
Another example:
And now, when I have more "R" so it's display everything:
So how can I display everything when I have same or less "R" (it can b R or any letter) ?
https://docs.google.com/spreadsheets/d/1svXFqHVtbgMfHPZjxS3X9AKW679AqrVyMDySay2lzfw/edit?usp=sharing
Thanks for your help

Try
=QUERY(arrayformula(to_text(H1:J6)),"WHERE Col3 IS NOT NULL " ,0)
the problem comes from a combination of string and numeric value in the same column (date is numeric), query does not work well and you have to convert data into strings. Because the source is now a function, you will have to use Colx instead of letter of column.

Related

google sheet : query to return row number rather than the value itself

I have this formula :
=filter(A10:A, R10:R=S10:S)
It will extract all data from column A with condition where the value of column R and S are equal. It works fine but i want it to output the row number rather than the value in column A.
How can i do this ?
Thanks
Use this:
=FILTER(ROW(A10:A), R10:R=S10:S)

Comparing dates in Google Sheets QUERY() formula

Looking for some assistance please.
To start, here's the function that I'm having trouble with:
=IFERROR(
QUERY(
OrderDetails!A8:Q9,
"SELECT SUM(J) where Q >= date '" & TEXT(D3,"yyyy-mm-dd") & "' label sum(J) ''"
),
0
)
The dates in the data range (OrderDetails!A8:Q9, columns P is Date & Q is DateOnly) look like this:
I added Q manually in an attempt to make the date-matching work, but P is the raw data which I would prefer to use.
Next the SUM(J) which are just order balances. If I remove the WHERE clause the query runs as expected.
D3 is the column date I want to match to, in the format: 8/13/2018, however I've formatted it on screen to be only DDD.
To show the actual value rather than the header in the cell, I've used label sum(J) ' '.
When running I get the message "Nothing to return".
Can anybody spot an obvious error with the code or my approach? Happy to add any further detail if needed.
Populate Q8 with:
=left(P8,10)*1
and copy down.
The QUERY is failing for attempting to compare a date (in D2/3) with the output of a string function (LEFT). *1 coerces the strings into dates. Left alignment was a clue that the contents were Text.

How to refer to column 'BY' in query?

In my Google spreadsheet, i'm using the query function to get data from one sheet onto another. The query looks something like this:
=QUERY('mySheet'!$A$1:100,"select F where "&C$3&"='myValue'")
This works fine until cell C3 has value "BY" (because the word "by" has significance in the query language). I've tried using single quotes, but then the query uses header "BY" instead of column BY and it returns an empty result.
Any ideas on how to work around this?
Put it in backticks.
=sum(QUERY(select `BY` where `BY` is not null limit 7))
This will sum the first 7 values in column BY.
(This was fun to debug. The formula worked in every other column...)
"BY" is a special word. It is present in clause group by
You may use this:
=QUERY({'mySheet'!$A$1:100},"select Col5 where Col"&C$3&"='myValue'", 0)
and paste the column number into C$3
see more info here
BTW you may use function column() to know BY is column 77 or find the right number by header name: =match("column name", 'mySheet'!1:1, 0)

QUERY using cell contents as SQL variables

Here is what the spreadsheet I'm working with looks like:
Summary table
(top of sheet)
Source data
(same sheet, below output)
I'm using the QUERY function to populate the appropriate feeds in the summary table with the data starting at A24 needs to be placed into.
Here is the formula I'm using in cell C6 (similar formulas are used throughout the summary table):
=QUERY($A$24:$D$57, "Select D Where B='ENQ' and A='2/27/14 - Thu'")
This gets the right information, but the formula needs to be edited to be unique in each cell it's used in. The problem being unable to quickly populate the cells with A='2/27/14 - Thu' being too specific.
I was trying to set it up so that:
date in A would compare with dates found on headers in ROW 2 before accepting data
room type in B would compare with value from A in each row of the summary table
How can the QUERY function be written to refer to these values as variables, instead of using the literal strings in my original function?
Instead of fixed strings such as 'ENQ', you can have your formula refer to the index in column A of your output. For example, you could change your formula to this, in cell C4:
=QUERY($A$24:$D, "Select D Where B='" & $A4 & "' and A='2/27/14 - Thu'")
^^^^^^^
The ampersand (&) is used to concatenate string segments.
Note that since the source data extends to the bottom of the data range of the sheet, we can forego specifying the bottom row. The range $A$24:$D will take in all rows, so it will automatically adjust to additional source data.
To compare dates, both values need to be dates. "2/27/14 - Thu" is not recognized as a date in your source data sheet, but as text, even though you've set the numeric format to date. So make sure you change all your source data to have actual dates in column A.
You can still have your dates formatted the way you like - see this screenshot. The content of A2 is now a proper date, "2/27/2014", but the format is set to display "mm/dd/yy - DDD". As long as the data is a date, the query can be built using the spreadsheet TEXT function to interpret the date in its yyyy-mm-dd format.
With dates in your source column, you can use todate() scalar function to tell QUERY to convert the date in the source to a query-date, and the date keyword to treat the following literal string (from C2) as a date.
The resulting function for cell C4 is:
=QUERY($A$24:$D , "Select D Where B='" & $A4 & "'and todate(A) = date '" & TEXT($C$2,"yyyy-MM-dd") & "'")
^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Similarly, for D4:
=QUERY($A$24:$D , "Select C Where B='"&$A4&"'and todate(A) = date '"&TEXT($C$2,"yyyy-MM-dd")&"'")
Your calculations in column E can be improved to handle #N/A results appearing in columns C or D:
=if(isna(C12*D12),0,C12*D12)

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