I'm building a Google Sheet table and I am stuck on a specific query I want to make
Source Table pic here
I need to sort my Names by "Type" and by "ValueType".
I managed to sort them by "Type" with ease, but i'm stuck on the sort by "ValueType" part, because they are in columns, not lines and I can't manage to find a way to sort them by columns
My Query looks like this right now
=QUERY(A1:G8; "SELECT * WHERE A='Type1'; 1)
I want it to look something like this :
=QUERY(A1:G8; "SELECT * WHERE A='Type1' AND C1:G1='ValueType 1'"; 1)
Is it possible to do something like this, and if so, can you please tell me what is the syntax?
Thanks in advance.
=QUERY(A1:G8; "SELECT * WHERE A='Type1' AND (C='"&C$1&"' or D='"&D$1&"') "; 1)
adding or X='"&X$1&"' within the () where X is the next letter.
'"&C$1&"' is the value in cell C$1 but you can adapt that for a different value on your sheet, or a fixed value using C='xxx'
You need to expand the formula, or you can do it too (if the number of columns is not fixed)
=QUERY({A1:G8}, "SELECT * WHERE Col1='Type1' and (" & "Col"&arrayformula(TEXTJOIN("='ValueType 1' or Col",,column(C:G)))&"='ValueType 1' )", 1)
try just that sentence to understand how it has been built
="Col"&arrayformula(TEXTJOIN("='ValueType 1' or Col",,column(C:G)))&"='ValueType 1'"
Related
Sorry I know this question has been asked before - I have tried changing my query around but can't seem to get it to work as expected, doesn't look to be anything wrong..
I am simply trying to query data from one large master sheet into a few separate sheets. I am using importrange to get the data from sheet, and a simple select query to filter by one of the columns. If I do a select * I get all the data as expected, but can't use a WHERE clause with any column (I just need 1 of the columns, but I tried with a few different ones).
Appreciate any help!
Query:
=QUERY(IMPORTRANGE("1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk","Sheet1!B:I"),"select * WHERE 'Rank'='LTC' ")
Columns
Username Rank Time In Service TIS Time In Grade TIG Promotable Awards PLT/SQD
Source sheet: https://docs.google.com/spreadsheets/d/1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk
Test sheet: https://docs.google.com/spreadsheets/d/1UCucsfE0M4j95d_47iN0LrAhS0luv8wXVMHRVTHJHRQ
As player0 stated, you should refer to the columns by its number, you can select multiple columns and state multiple "where" statements by using Col1,Col2, etc respectively. In this case: Where Col2 = 'LTZ'
try:
=QUERY({IMPORTRANGE("1sNA9u2uQW-XjEKjrVS2a5LtTPCchwSuTkXfjhTJtvPk", "Sheet1!B:I")},
"where Col1='LTC' ", )
Hello I need help with named range in google sheet...
=QUERY(Data,"SELECT C,D,E,SUM(G),L,SUM(G*M) WHERE A = '"&$A$1&"' AND E = '"&$B$1&"' GROUP BY C,D,E,L",1)
I'd like to calculate columnG*columnM and than SUM this results when grouping.
This works fine before I start grouping table. I could do columnG*columnM get result and use another QUERY but don't like the idea of using many helpers. Is it even possible?
Could you provide a link to your project ? I make a simplified example : if you need the sum of ColumnB x ColumnC, you have to add to your data an extra column as following
=query({A2:C,arrayformula(B2:B*C2:C)},"select SUM(Col4) group by Col1 ")
and then usie ColX instead of A,B,C and the extra column D.
is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.
I have been working on this issue for a few weeks now and can't seem to find a solution. I used this answer (IMPORTRANGE with CONDITIONS) to get as far as I could, but I keep getting a value error.
This is the sheet I'm working with.
My goal is to use the first tab in the sheet (All Games) to enter all the games that I come across to create a compendium. But, then I want it to automatically populate the other tabs based on certain criteria (what type of game, skills learned, etc.)
On the Warm-Ups tab you'll see the formulas I have tried. A1 is the most recent.
Here is the formula I tried:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag/edit#gid=1359689553", "All Games!A1:A1300"),"SELECT Col1 WHERE (Col2 = 'w') ")
I am getting a value error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Col2
you are trying to reference Col2 but you selected range A1:A1300 which is just 1 column. therefore try:
=QUERY(IMPORTRANGE("1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag", "All Games!A1:B1300"),
"SELECT Col1 WHERE (Col2 = 'w') ")
from the brief look on your sheet, you may want use matches or contains instead of = in your QUERY
You are only importing (part of) ColumnA - so no wonder Google can't find a second column :)
In Google Spreadsheet, I have the expression:
=QUERY(database; "select b,c, where a='anyone-condition' order by c desc";-1)
The column a,b are strings and c is a number.
How can I include in this query one calculated field, c/sum(c)?
Although Ed Nelson is perfectly right, you can be creative with multiple nested Queries and get desire result without an extra column.
I have build simple example that will show you the way
Data
Solution 1 - simpler but with ugly column name
=QUERY(
A1:C3,"select A,B,C/"&QUERY(
QUERY(A1:C3,"select sum(C)"),"select * offset 1",0)&"" ,1
)
Solution 1.1 - more complex but with custom column name
=QUERY(
A1:C3,"select A,B,C/"&QUERY(
QUERY(A1:C3,"select sum(C)"),"select * offset 1",0)&
" label C/"&QUERY(
QUERY(A1:C3,"select sum(C)"),"select * offset 1",0)&
" 'C/sum'",1
)
Finals:
You can go further and add formating to last column as well
Link to working copy
For your specific example probably code should be like this:
=query(database; "select b,"&query(query(database; "select sum(c), where a='anyone-condition' "),"select * offset 1",0)&" where a='anyone-condition' order by c desc";-1)
But, it should be tested against real data
Is that serves your needs?
You can't do a sum without doing a group which you don't want. You can add a column D to your sheet to sum. Try =sum($C$2:$C) in D and copy down. Then this will work:
=query(database, "select B,C/D where A='anyone-condition' order by C desc label C/D ''",-1)
The problem is with the Google Spreadsheet 'kernel', not with my coding. Look the scream that I printed
https://drive.google.com/file/d/1yJbcfVZ1tDmW8WoG224PALRIwyEbX9LH/view?usp=sharing