Google Sheets Query and Comma Separated Data - google-sheets

I have a simple data query in a Google Sheet:
=query('2019'!$A$2:$A,"select A")
The data in column A has multiple cells that contain comma-separated values. Only the data in the first cell (A2) returns with all of the comma-separated values. How do I get all of the data returned in this query?

It's very likely the problem is cause because the data without commas are of ty numbers, boolean, dates, time, duration, in other works, they are not text values.
This happens because QUERY assigns a data type for each column based on a sample of each column data. If the column includes data of different type, they aren't included.
The way to solve this is to prior adding the data to QUERY convert all the column values to the same data type, in this case all should be text. To force that all the values are treated as text you could preppend and apostrophe / single quote. Other methods are
set the cell number formatting to plain text
concatenate the cell value to an empty text "" like =A1&""

try like this:
=ARRAYFORMULA(QUERY(TO_TEXT(2019!A2:A), "select A", 0)

Related

Last value of a column in Google Sheets

I was trying to use the following function;
=INDEX(D:D,COUNTA(D:D),1),
in order to get the last currency value of a column, but it returns #ERROR!.
The value im trying to extract
As I montly update this spreadsheet, it would make it very convenient if would etract the last value in the column, e.g. the value marked in the image.
Is there a way (in Google Sheets) to find the last non-empty cell in this column, such that when I update the spreadsheet with a new "last value" it would return that value?
The index(counta()) pattern will fail when the data is sparse, i.e., when there are blank values in the column.
The index(match()) pattern will fail when the data contains a value that is not a number.
To find the last non-blank value in column D, regardless of data type, use the +sort(row()) pattern:
=+sort(D1:D; not(isblank(D1:D)) * row(D1:D); false)
The formula uses semicolons as argument separators to make it work in any locale.
If the column has only currency (ie number) values then you can use something like:
=INDEX(D1:D, MATCH(999^99, D1:D))
or try:
=SORTN(D:D; 1;;ROW(D:D)*(D:D<>""); )

vlookup a value and return if it is after a certain date

Hello I Have a sheet with a list of names, medications, statuses and correlating dates on a spreadsheet. On a separate spreadsheet I would like to be able to type in a date and status (ex. "Pending", "active") and have the correlating patient names come up.
If i Type in 5/6/21 and then "active" I would like the formula to search the master-sheet and return names of patients whos status is "Active" after the Date 5/6/21.
I can't open your second sheet, but based on the first one, I've added a date input in cell F2.
Sheets QUERY is a powerful function that is similar to SQL. It can be used to display data from a dataset based on certain parameters (like your date search, and status = active).
In the example, the following QUERY formula goes in cell H1, but you can move it to a different tab if needed, obviously referencing 'DATA'!A:E etc.
=if(isblank(F2),,iferror(query(A:E,"where D > date '"&text(F2,"yyyy-mm-dd")&"' and lower(E) contains 'active' order by D,A",1),"No result"))
functions
isblank - if cell F2 is blank (the date search), then nothing.
iferror - if the query doesn't return any values, just output the wording 'No result'.
query function - as per the parameters below.
The range of your data is cells A:E.
The where clause basically says that the value in col D needs to be greater than the date within the single quotes '', which contains "&text(F2,"yyyy-mm-dd")&", which is the value of cell F2, formatted as text in the structure yyy-mmm-dd.
Placing "&<Sheets function>&" within the single quotes '' allows you to put another Sheets function in the query syntax, in this example the text function that formats the input of cell F2 as a date yyyy-mm-dd.
The where clause also includes an and where the lowercase of column E, lower(E) contains the word 'active'.
The results are ordered by column D then column A.
The ,1 at the end of the query tells it to treat the first row of data as headings. If it was data and not a heading, then it would be ,0.
Let me know if you need it implementing on your actual sheet.

Array Formula messing with Query Table

When I add an array formula to a column which is used to generate a query table, the query table doesn't sort the data as expected. When I remove the array formula it displays correctly.
The document is here: https://docs.google.com/spreadsheets/d/1r3bpNFy9k1h8anZJfefk6KrGYSy7mW2izxKQZb9mWoU/edit?usp=sharing
An example of the error:
If I add an array formula to 'Book Rating'!J:J, the results of the query at 'Book League'!K1 (and E13 and H13) no longer order the books in the desired Desc order. When I remove the array, they order correctly. This type of problem is repeated throughout the sheet for all of the respective League tabs - e.g. at 'Chefs League'!A1.
Can someone help me understand why these Query tables are being messed up by the Array formulas?
The issue is happening because of the nature of QUERYs, in that each column of a QUERY can only return one type of data (e.g., text or numbers, but not both). In the case where multiple data types exist in one column, QUERY will return the most populous type for the column. In your case, you've inserted "-" in place of null, and that is text. I'm guessing that your array formula filled the entire column of empty cells after your data set with that hyphen, making text the most populous type for the column. Therefore, all of your percentages were being converted to text. And in descending order of text, for instance, 9.25% (as a string) is "higher" than 25%, because the former begins with "9" and the latter begins with "2."
One way to resolve the issue would be to remove the "-" from your 'Book Rating'!J2 array formula and replace it with IFERROR(1/0), which will leave those cells null instead of filled with a hyphen. This will leave numbers as the most populous type for the column and your QUERY will work as expected.
Using E13 as an example, here was your original formula:
=Query('Book Rating'!$A$1:$K,"Select A,J where A<>'' Order by J Desc Limit 10")
If you want to leave that hyphen running in the array formula, here are some ways to leave the 'Book Rating'!J2 array formula as I suspect you had it, instead changing your QUERY formula:
1.) Pre-FILTER the 'Book Rating' data before performing the QUERY:
=Query(FILTER('Book Rating'!$A:$K,'Book Rating'!J:J<>"-"),"Select Col1,Col10 Where Col1 <> '' Order by Col10 Desc Limit 10",1)
2.) Use SORTN and FILTER together instead of QUERY, since FILTER can handle multiple data types in the same column:
=ArrayFormula({"Books","6 Stars";SORTN(FILTER({'Book Rating'!A2:A,'Book Rating'!J2:J},ISNUMBER('Book Rating'!J2:J)),10,0,2,0)})

Google Sheets: Query function can't copy data

I attached a sample Google Sheet data (Link).
It contains 2 sheets. The Response sheet contains the response of the Google Form. Since the Google form has a lot of repeating questions, I have to transform the data using the Query function (sheet Transformed cell B2). The query command is
=QUERY(
{
Response!E2:H,Response!B2:D;
Response!I2:L,Response!B2:D;
Response!M2:P,Response!B2:D;
Response!Q2:T,Response!B2:D;
Response!U2:X,Response!B2:D;
Response!Z2:AC,Response!B2:D;
Response!AD2:AG,Response!B2:D;
Response!AH2:AK,Response!B2:D;
Response!AL2:AO,Response!B2:D;
Response!AP2:AS,Response!B2:D;
Response!AU2:AX,Response!B2:D;
Response!AY2:BB,Response!B2:D;
Response!BC2:BF,Response!B2:D;
Response!BG2:BJ,Response!B2:D;
Response!BK2:BN,Response!B2:D;
Response!BP2:BS,Response!B2:D;
Response!BT2:BW,Response!B2:D;
Response!BX2:CA,Response!B2:D;
Response!CB2:CE,Response!B2:D;
Response!CF2:CI,Response!B2:D;
Response!CK2:CN,Response!B2:D;
Response!CO2:CR,Response!B2:D;
Response!CS2:CV,Response!B2:D;
Response!CW2:CZ,Response!B2:D;
Response!DA2:DD,Response!B2:D
},
"select * where Col1 <> '' Order By Col6"
)
However when you look at the sheet Transformed, some data in Col F (Corresponding to Response sheet Col B) didn't get transferred. How could this problem be fixed?
Thanks in advance
It is often noted that users are tempted to mix data types within a column. The query() function will give undesirable output. If a column is intended for numeric values then only numerical values must reside in that column. Date columns must only contain dates and text columns only contain text values.
This does not mean that numbers cannot appear in a text column as long as they are in a text format.
Generally, the query() function will assume the greater number of cell types in a column to be that data type. For example, if there are 100 numbers and 20 text values in the same column then a numeric value will be assumed for that column. There is a good chance the text values will just be ignored. A slight change in your formula will convert all values to text.
See if this helps
=ArrayFormula(QUERY(to_text({
Response!E2:H,Response!B2:D;
Response!I2:L,Response!B2:D;
Response!M2:P,Response!B2:D;
Response!Q2:T,Response!B2:D;
Response!U2:X,Response!B2:D;
Response!Z2:AC,Response!B2:D;
Response!AD2:AG,Response!B2:D;
Response!AH2:AK,Response!B2:D;
Response!AL2:AO,Response!B2:D;
Response!AP2:AS,Response!B2:D;
Response!AU2:AX,Response!B2:D;
Response!AY2:BB,Response!B2:D;
Response!BC2:BF,Response!B2:D;
Response!BG2:BJ,Response!B2:D;
Response!BK2:BN,Response!B2:D;
Response!BP2:BS,Response!B2:D;
Response!BT2:BW,Response!B2:D;
Response!BX2:CA,Response!B2:D;
Response!CB2:CE,Response!B2:D;
Response!CF2:CI,Response!B2:D;
Response!CK2:CN,Response!B2:D;
Response!CO2:CR,Response!B2:D;
Response!CS2:CV,Response!B2:D;
Response!CW2:CZ,Response!B2:D;
Response!DA2:DD,Response!B2:D}),"select * where Col1 <> '' Order By Col6"))

Reduce a range of values to a list in Google Sheets

I have a table with printer names and the model numbers of the toner and drums which they use. I'm looking for a way to generate a single column list from this range of values, excluding blank cells. Below is the table:
I'd like to end up with a list of values as such:
MX-C30NT-B
MX-C30NT-C
MX-C30NT-M
MX-C30NT-Y
MX-C30DR
MX-C30HB
MX-C30NV-B
MX-C30NV-C
MX-C30NV-M
MX-C30NV-Y
...
I know in Excel I can use an array formula to accomplish this, but array formulas don't seem to be as robust in Sheets. Is there a formula which will perform this conversion?
Combining nonempty cells in columns E-M into a single column, ignoring the header row:
=filter({E2:E; F2:F; G2:G; H2:H; I2:I; J2:J; K2:K; L2:L; M2:M}, len({E2:E; F2:F; G2:G; H2:H; I2:I; J2:J; K2:K; L2:L; M2:M}))
The first argument is just a bunch of column stacked; the filter excludes empty ones. Note that the second {...} construct is identical to the first, it's a copy-paste.

Resources