my starting table looks similar to the following
Person 1, 75
Person 2, 48
Person 3,
Person 4, 82
Person 5,
Person 6, 93
...
I now try to include in following query a "where" statement to exclude entities that have no numeric value. This is what I currently have to show me the lowest 5 values of the set above and it works so far
=QUERY('DPS Transpose Tables'!D1:E29;"select D, max(E) group by D order by max(E) asc limit 5 label max(E) ''";0)
How can I add something like this that works
=QUERY('DPS Transpose Tables'!D1:E29;"select D where (E<>"" OR Is not NULL), max(E) group by D order by max(E) asc limit 5 label max(E) ''";0)
Thanks a million in advance!
Try 'where E >=0' like this:
=QUERY('DPS Transpose Tables'!D1:E29,"select D, max(E) where E >=0 group by D order by max(E) asc limit 5 label max(E) ''",0)
You can also try 'WHERE IS NOT NULL'
Sometimes I find using the >= 0 does not get the desired results
=QUERY('DPS Transpose Tables'!D1:E29,"select D, max(E) where E IS NOT NULL group by D order by max(E) asc limit 5 label max(E) ''",0)
Use NOT Equal To and '' empty string with single '' combination
Where E <> ''
Related
I need to review this query:
=QUERY('BD3'!A:Q, "SELECT D,Q, SUM(M) WHERE I='W34' AND M>0 AND L='Huacho' GROUP BY D,Q ORDER BY SUM(M) DESC LIMIT 5",-1)
I obtain this:
But I need something like this:
For the result you want, the correct SQL function should be:
RANK() OVER (PARTITION BY D, Q ORDER BY SUM(M) DESC
You can check this answer for detail explanations:
Array Formula to Rank Column A Partition by Column B And C
Say I have a table with two columns: name and age, and that the table's rows are ordered by age.
I need a function to find the name of the youngest person who is at least 50 years old.
Example
For this list:
Name
Age
Nordom
3
Annah
19
Ignus
56
Morte
72
We'd get "Ignus".
As you said age column is sorted so can try below formula.
=INDEX(FILTER(A2:A5,B2:B5>=50),1)
Try this:
=query(B3:C,"select B,C where C > "&E3&" order by C limit 1")
If you want just Ingus with no headers and age, you can do:
=query(B3:C,"select B where C > "&E3&" order by C limit 1",0)
use:
=QUERY(A:B; "select A where B >= 50 limit 1")
I can get the counts for column E (there are no empty cells in the range) with
=QUERY(Sheet1!D2:H,"select D, count(E) where F = 'person-person' group by D")
But if I add a second where clause
=QUERY(Sheet1!D2:H,"select D, count(E) where F = 'person-person' and H = 'Acquaintence' group by D")
I am missing the zero counts which I need
Thanks for any assistance with this
Google sheet w/data
https://docs.google.com/spreadsheets/d/1p0gM4fHWjPf9k40h_GrJjqj8KrxSJDQ-E10LAOgS--Y/edit?usp=sharing
Try this:
=ARRAYFORMULA(QUERY({Sheet1!D2:D,N(Sheet1!F2:F&Sheet1!H2:H="person-personAcquaintence")},"select Col1,SUM(Col2) where Col1<>'' group by Col1"))
SUM()'ing in a query lets you show 0s in a way that counting doesn't really.
I am trying to discern the base percentage points change in two columns in a query statement and then order by the results.
I have tried to label the result and Order By that label, but this doesn't work.
=QUERY('Sample Sheet'!A:I,"SELECT A,B, ((I-H)/H)*10000 LIMIT 5")
I would like the ((I-H)/H)*10000 to be that which I order by. Currently, the Limit statement brings the top 5 results. I don't want to Order By H or I because it is the change in the two numbers I want to display.
Any help would be much appreciated!
=QUERY(A:I,"SELECT A,B, ((I-H)/H)*10000 WHERE A IS NOT NULL ORDER BY ((I-H)/H)*10000 LIMIT 5",1)
ORDER BY can be used with the same expression used in SELECT
you could use double query and have it nice and clean like:
=QUERY(QUERY('Sample Sheet'!A:I,
"select A,B,((I-H)/H)*10000", 1),
"order by Col3 desc
limit 5
label Col3'equation'", 1)
but if you prefer one query then:
=QUERY('Sample Sheet'!A:I,
"select A,B,((I-H)/H)*10000
order by ((I-H)/H)*10000 desc
limit 5
label ((I-H)/H)*10000'equation'", 1)
I want to make a report: "select salesmen who have N recent Status codes = 2,3,4,5".
A structural example of my data has 35 rows (including 1 header row):
link.
This file has a Date, Sales code (id of a salesman), Status code (id of how successful a transaction was) and other fields which are not necessary for the purpose.
I ended up using three formulas:
a QUERY function with IMPORTRANGE.In the example data it is slightly simpler - take only Sales Codes, Status Code, and Date from another sheet, then order by Date, Sales Code. Formula in A9:
=QUERY({Source!D1:E, Source!A1:A}, $B$4, 1)
an additional column with a sequentional numbering. Formula in D10:
=ArrayFormula(if(len(A10:A), ROW(A10:A) - MATCH(A10:A,A10:A,0) - 8, ))
a QUERY function to extract only N cases (let's say 5). Formula in F9:
=QUERY(A9:D, "select A, B where D <="&B3, 1)
Is there a way to combine all 3 steps into one so I get the output like in F10:G24 using one (and hopefully fast :)) formula? The formula I tried (expanded for readability):
=QUERY(
{
QUERY({Source!D1:E, Source!A1:A}, $B$4, 1),
ArrayFormula(
IF(len(J10:J),
ROW(J10:J) - MATCH(J10:J, J10:J, 0) - 8,
)
)
},
"select Col1, Col2 where Col4 <="&B3,
1
)
It gives me the error:
"Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 28. Actual: 991."
I also tried finite data ranges in ROW() and MATCH() but that yields an empty table.
In the original database there are ~3500 rows and they will expand, so I think I should stick to infinite ranges to automate data extraction.
Hm well it's a bit of a nightmare TBH - a similar question has cropped up before but no easy answer. Here is a draft which involves repeating the basic query several times-
=ArrayFormula(query({query(A2:E,"select * where E>=2 and E<=5 order by D, A desc"),
row(indirect("2:"&count(filter(E2:E,E2:E>=2,E2:E<=5))+1))-
match(query(A2:E,"select D where E>=2 and E<=5 order by D, A desc"),
query(A2:E,"select D where E>=2 and E<=5 order by D, A desc"),0)
},"select * where Col6<=5"))
But needs looking at more to see if it can be simplified.
This is the full-column version including headers - I think it's OK
=ArrayFormula(query({query(A:E,"select * where E>=2 and E<=5 order by D, A desc"),
row(indirect("1:"&count(filter(E:E,E:E>=2,E:E<=5))+1))+1-
match(query(A:E,"select D where E>=2 and E<=5 order by D, A desc"),
query(A:E,"select D where E>=2 and E<=5 order by D, A desc"),0)
},"select * where Col6<=5"))