This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
I have a google sheet https://docs.google.com/spreadsheets/d/1mUV9DpVJHC2UbyqOG49wUIRj3EflTlB9etJQFssRLvo/ with a column "Floor", it contains the number and also character, I want to query the column and remove all empty cell, =unique(query(A:A,"SELECT A WHERE A IS NOT NULL ORDER BY A")) only the number be queried and all characters have been removed.
Can anyone advise how I can query all with unique and sort function?
I read the article from https://webapps.stackexchange.com/questions/101778/google-sheets-query-wont-display-cell-text-if-other-cells-have-numbers and come up a solution, hope this can help others.
=UNIQUE(ARRAYFORMULA(QUERY(TO_TEXT(A2:A), "SELECT Col1 WHERE Col1 IS NOT NULL ORDER BY Col1")))
Reason of using TO_TEXT() because mixed data types in a single column in Google Sheet, the majority data type determines the data type of the column for query purposes, so I convert all into text format.
Ref: https://support.google.com/docs/answer/3094285?hl=en
UNIQUE is used to filter out all duplicated values
Regarding ARRAYFORMULA() function, I don't know why it is needed but QUERY() will return #VALUE! if missing the ARRAYFORMULA().
If someone can explain the use of ARRAYFORMULA() and Col1 reference, appreciate to answer.
use the filter function instead.
considering Column A has both numbers and characters.
in B2, write: =filter(A2:A,isnumber(A2:A))
let me know if you need help!
Related
This question already has answers here:
Stacking Multiple Arrays In Query/Lambda Function
(2 answers)
Closed 3 months ago.
First of all this is my first question here...
Ok, and now my problem:
I created a formula that generates a dynamic Query if you are searching for data in multiple sheets. I just write the names of the sheets in green field and it changes the Query.
The text for the Query is correct, but now I want this to by the actual formula in a cell to display the data.
If I use the = and add the cell with the Query text, it copy the text. I tried the INDIRECT formula, but it does the same.
How can I use a this dynamic text to be my Query to dispaly the data depending on the amount of names in the green field?
EDIT: As advised by user doubleunary (as mentioned, this is my first time), I'm going to rephrase the problem.
In an spreadsheet a manager imputs for every task the amount a worker has made. He creates an new sheet for each date and imputs the data for that day. Each day can have different rows of data. The boss wants a spreadsheet that display in one sheet all that has been done in the current month. I used Query because you can easy join data from multiple sheets and ignor the empty rows.
But the problem is, that every day a new sheet is added with a new "name" (date). And the easyest way I found tho make a dynamic Query, without the Boss to manualy edit the Query, was to create a text with TEXTJOIN formula, in witch he ony needs to enter the new "name" (date).
If there is a better was, please share, but it should not be in App Script if possible.
Thank you.
Easily you can't transform a text into a formula.
In this case, you should create the query formula and insert the ranges with Indirect function, like this:
=Query({Importrange(LINK,Indirect("'"&O4&"'!I38:S107"));Importrange(LINK,Indirect("'"&O5&"'!I38:S107"))},"Select * Where Col1 is not null",0)
If the formula you quote and the data sheets are all in the same spreadsheet file, you should not to use importrange() but indirect(), like this:
=query(
{
indirect(O4 & "!I38:S107");
indirect(O5 & "!I38:S107")
},
"where Col1 is not null",
0
)
In the event the row references such as I38:S107 change from time to time as well, you can put those references in a cell and refer to them the same way.
try (assuming url is same for all sheets):
=QUERY(LAMBDA(x, QUERY(REDUCE(SEQUENCE(1, 11), x,
LAMBDA(a, c, {a; IMPORTRANGE("url", c"!I38:S107")})),
"where Col1 is not null", 1))
(O4:INDEX(O:O, MAX((O:O<>"")*ROW(O:O)))), "offset 1", )
more examples: https://stackoverflow.com/a/74280310/5632629
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Google spreadsheets query() is replacing text with null for mostly numeric columns [duplicate]
(3 answers)
Closed 5 months ago.
I am using query import range to pull through data from another spreadsheet which works apart from when a different type of value is needed eg. 1234 or
12345 would return correctly but values like this RIFG_PI9926 or COHJRI4426 are left blank.
I am thinking it is a formatting issue but playing around with format settings it makes no difference.
My next thought is to use the query to force results in the original format to see if that will allow them to pull through correctly.
This is what I have so far but returns blanks
=QUERY(IMPORTRANGE("url","Sheet!A2:L"),"select Col4,Col7,Col1,Col2, Col3,Col9",0)
Col7 is the problematic column
When I recreated a similar test it worked fine with the above formula which makes me think that is is definitely the formatting in some way
this is a know QUERY issue occurring whenever you have a mixed dataset (numeric number with text strings)
sometimes it's enough just:
=QUERY({IMPORTRANGE("URL", "Sheet!A2:L")},
"select Col4,Col7,Col1,Col2,Col3,Col9 where Col7 is not null", 0)
but mostly you will need to convert your dataset into one type:
=INDEX(QUERY(TO_TEXT(IMPORTRANGE("URL", "Sheet!A2:L")),
"select Col4,Col7,Col1,Col2,Col3,Col9 where Col7 is not null", 0))
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
I have a simple Query that groups my data by months that was working fine before, but now that I've introduced a formula into my date column, it's not working anymore. (I'm guessing it's because the majority data in the column is now formulas instead of actual dates).
=Query(C5:L,"SELECT SUM(I) pivot MONTH(C)+1",1)
Is there a way for me to still get my intended Query data without removing my formulas in the date column? (Query formula is in M2)
Thank you in advance!
Link to sheet: https://docs.google.com/spreadsheets/d/1EpvLMboKJ0KeR7tTqBarF1AnAg3jelhKTkyBhwKNlK4/edit#gid=1335125620
Your formulas in Col C seem to be causing the issue since they're adding a blank space when there is no corresponding value in Col D:
=IF(D45=""," ",TIMESTAMP())
Instead, try:
=IF(D45="",,TIMESTAMP())
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
Here is a copy of my sheet https://docs.google.com/spreadsheets/d/1b7ofD9f02yKiIvGYfCBi_GdhkRtgTAoY2NpftJmZaDQ/edit?usp=sharing
So my query is on the front tab 'Overall' in D1
=query(Data!A1:G,"SELECT * WHERE 1=1 "&IF(A2="All Raids",""," AND A contains "&A2&" ") &IF(B2="All Classes",""," AND LOWER(B) = LOWER('"&B2&"') "),1)
On the datasheet, I have people listen in raids 1,2 and 3.. and it works fine. However, if I were to change a value to something like BWL1 or BWL2, it will not display.
I got this code from a youtube tutorial, so I don't understand it 100%, but basically the "a2=all raids","" part is just to remove any filters, then the remaining is filtered by my drop-down menus, &A2& and &B2&.
Any ideas?
I've tried using A CONTAINS "&A2" instead of A = "&A2&", I just cant figure out a workaround to where any value (numberical+lettered) listed in my Datasheet column A works.
Thank you in advance for your time, I hope this makes sense :)
That's a known issue with query() function: query() has trouble with mixed datatypes (numeric and text in column A). To avoid this you can convert column A to text. See if this formula works
=query({ArrayFormula(to_text(Data!A1:A)), Data!B1:G},"SELECT * WHERE 1=1 "&IF(A2="All Raids","", " AND Col1 contains '"&A2&"'") &IF(B2="All Classes",""," AND LOWER(Col2) = LOWER('"&B2&"') "),1)
Note that, because of the use of 'contains' when '1' is selected in A2, it will also show rows containing BWL1. If you don't want that, change 'contains' to '='.
This question already has answers here:
Google Sheets QUERY Function: Select Columns by Name
(2 answers)
Closed 4 months ago.
newbie question, is it possible to select columns by name rather than letter when using Google Query Language with Google Spreadsheets?
This works fine for me: "SELECT A, COUNT(B) GROUP BY A"
It'd be great if I could use the column headers in the first row, more like a database, as in:
"SELECT student, COUNT(detention) GROUP BY student"
I suspect it's not possible, but hope this yet another case where my Internet search skills failed me.
This is currently not possible. The GQL documentation states[1] "Columns are referenced by the identifiers (not by labels). For example, in a Google Spreadsheet, column identifiers are the one or two character column letter (A, B, C, ...)."
If you want to do this in a spreadsheet it is possible with the following formula to convert a column header name into a letter (some tweaking might be required +1 (might be +2)). It also relies on column headers being unique and not containing commas
=REGEXEXTRACT(ADDRESS(1,COUNTA(SPLIT(LEFT(JOIN(",",TRANSPOSE(1:1)),FIND("your_column_name",JOIN(",",TRANSPOSE(1:1)))),","))+1,4);"[a-zA-Z]+")
[1] https://developers.google.com/chart/interactive/docs/querylanguage#Select
A little simpler:
SELECT "&SUBSTITUTE(ADDRESS(1,MATCH("student",Sheet1!A1:B1,0),4),1,"")&", COUNT("&SUBSTITUTE(ADDRESS(1,MATCH("detention",Sheet1!A1:B1,0),4),1,"")&") GROUP BY "&SUBSTITUTE(ADDRESS(1,MATCH("student",Sheet1!A1:B1,0),4),1,"")
Example in Google Sheets
Detailed explanation
I found that when you use IMPORTRANGE function on external ranges it converts from a letter to a column number, and will help you in this matter.
I've wanted to select a column based on its field name, but the problem for me was that the column to look at was likely to change in the future. So what I did was use the MATCH function to identify the column, so it looks something like
=QUERY(IMPORTRANGE("spreadsheet url","NamedRange"),"SELECT Col"&MATCH("FieldName",FieldNameRowAddress/RangeName,FALSE)")
The funny thing is you have to allow permission to access itself.
I've named my ranges that I'm importing to make it even more future proof.
if you really want you can fake it:
=LAMBDA(student, detention, QUERY({A1:B5},
"SELECT "&student&", COUNT("&detention&") GROUP BY "&student, 1))
("Col"&MATCH("student", A1:B1, ),
"Col"&MATCH("detention", A1:B1, ))