ROUNDUP SUM values in a column in Google Sheets' query - google-sheets

I want to ROUNDUP the sum values in a column in my google sheets QUERY. I discovered adding format sum(Col2) '#' will do the trick as long as the sum is >.5. So how do I accomplish the same result if the value is <.5?
Here is my formula:
=QUERY(QUERY(Data!A3:D, "SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D format sum(B) '#'", 0),"OFFSET 1",0)
Currently, if the result is <.5, it will just display a blank space.
Here is a sample sheet

the only possible way would be:
=ARRAYFORMULA(IFERROR(ROUNDUP(
QUERY(QUERY(Data!A3:D,
"SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D", 0),"OFFSET 1",0)),
QUERY(QUERY(Data!A3:D,
"SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D", 0),"OFFSET 1",0)))

Related

using ceiling function within Google Sheets QUERY

I'm trying to use the QUERY function in Google Sheets to summarize the data from another sheet.
I have a sheet named Expenses in which I list expenses by description, amount (column B) and the month in which the expense is to be paid (as a month name e.g. "January")(column C).
This formula works:
=query(Expenses!B1:C, "select C, sum(B) group by C order by C")
but I would like to
order by month chronologically,
add a column that rounds the amount up to the next $100.
Apparently the regular Sheets functions are not available within QUERY since it uses the "Google Visualization API" instead.
I've tried searching that API documentation for a "ceiling" function with no success. I've also not found a way to go from month name to month ordinal.
Suggestions?
Thanks.
try:
=ARRAYFORMULA(SPLIT(REGEXREPLACE(FLATTEN(QUERY(TRANSPOSE({
QUERY({Expenses!B1:B, TEXT(MONTH(Expenses!C1:C&1), "00×")&Expenses!C1:C},
"select Col2,sum(Col1) where Col1 is not null group by Col2 label sum(Col1)''", ),
ROUNDUP(QUERY({Expenses!B1:B, TEXT(MONTH(Expenses!C1:C&1), "00×")&Expenses!C1:C},
"select sum(Col1) where Col1 is not null group by Col2 label sum(Col1)''", ), -2)}),,9^9)),
"(^\d+×)", ), " "))
It is in fact possible to do rounding within a QUERY, but it needs to be done indirectly with a bit of maths. To do so, you have to exploit the (undocumented, I think) modulo operator (%). Replicating the answer given by player0:
=ArrayFormula(query(query(query({B:C,month(C:C&1)}, "select Col2, sum(Col1), Col3 where Col2 is not null group by Col2,Col3 order by Col3"),"select Col1,Col2,(Col2+100)-(Col2+100)%100"),"offset 1",0))
What we are doing here within the query is adding 100 to each amount, then from this subtracting (amount+100) modulo 100, which rounds the answer back down to the nearest hundred (achieving the same result as you requested). It should be possible to do account for other rounding scenarios by changing the addend and modulus accordingly.

SUM of comma separated numbers for each unique value

I'm trying to return the SUM of a set of numbers, which are comma seperated in another cell.
I'm listing out the unique values in column 1, and trying to SUM the numbers in column 2.
Client A 0,56.3,0,450,90,22.6,22.6,0,180,0,90,67.6,67.6,67.6,90,225,450
The expected outcome is 1879.3 for Client A.
But how can I do this for every new client and set of numbers added? I have tried a combination of SUM and SPLIT, but I can't get it work for every value in column A in an arrayformula.
Here is the file: https://docs.google.com/spreadsheets/d/1k8o_Ft59R44yQKOSY99AuAk8HDGTcRyiw2N9umONv3U/edit?usp=sharing
Thanks!
You could try:
=INDEX(QUERY(SPLIT(FLATTEN(A1:A&"|"&SPLIT(B1:B,",")),"|"),"Select Col1, Sum(Col2) where Col1 is not null and Col2 is not null group by Col1 label Col1 'Client', Sum(Col2) 'Total'"))
I've put the formula in F1 in your spreadsheet:

How to sum values for each day in google sheets

I want to make two columns one that has date and the other that has sum for the number of violations occurred on that day. Have a look at the data below.
use:
=QUERY({B:C}; "select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col1)''")

Counting the number of occurances of text in a range and summarize in a list

I'd like to use a formula to inspect a range of text values in a Google Sheet, and summarize the number of occurrences found for each unique value.
use:
=INDEX(QUERY(FLATTEN(A:C);
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"))

Search for lowest/highest value in the date array

What is the best formula to get the lowest and highest values from column C for every date?
Need to fill F and G columns as a result
Link:
https://docs.google.com/spreadsheets/d/1IxLit5vOf9FIjEp4TOEWLFNoCB4yS5mYXXMXo2tvtiM/edit?usp=sharing
try:
=ARRAYFORMULA(QUERY({LEFT(A2:A; 10)*1\C2:C};
"select Col1,min(Col2),max(Col2)
where Col2 is not null
group by Col1
label Col1'date'"))

Resources