Google Sheets - QUERY() - Sums of rows - google-sheets

Is it possible to use QUERY() to get the sums of rows into cells?
For example, I have
a b c d
1 2 3 2
3 4 2 6
4 6 3 3
and I want to use QUERY() to get:
8
15
16
Thanks!

This will sum the numerical values in the rows. It does not get the 'a':
=transpose(query(transpose(QUERY(A:D,"select * offset 1",0)),"select sum(Col1),sum(Col2),sum(Col3) label sum(Col1)'', sum(Col2)'',sum(Col3)''"))
Returns:
8
15
16
Here is my test spreadsheet:
https://docs.google.com/spreadsheets/d/1At60xluiG_JvNh9onPgxGt9TeWMJ8l00o2pwUxWbnBM/edit?usp=sharing

Related

G Sheet - From "Index Filter" to "Array Vlookup Filter"

Try to achieve: Vlookup (Table 2 > Table 1 ) to Match the Nth Occurrence in Google Sheets.
Table 1
TABLE 1
Data
value
a
10
a
20
a
30
a
40
b
50
c
60
c
70
Table 2
TABLE 2
Data
helper: count data occurrences value
a
1
a
2
a
3
a
4
b
1
c
1
c
2
Issue: The FILTER and INDEX combo works fine but (my understanding) can't be converted in an array-formula.
INDEX(FILTER($F$3:$G,$F$3:$F=A3),B3,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A4),B4,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A5),B5,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A6),B6,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A7),B7,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A8),B8,2)
INDEX(FILTER($F$3:$G,$F$3:$F=A9),B9,2)
TABLE 2
Data
data occurrences
INDEX FILTER
FORMULA RESULT
a
1
INDEX(FILTER($F$3:$G,$F$3:$F=A3),B3,2)
10
a
2
INDEX(FILTER($F$3:$G,$F$3:$F=A4),B4,2)
20
a
3
INDEX(FILTER($F$3:$G,$F$3:$F=A5),B5,2)
30
a
4
INDEX(FILTER($F$3:$G,$F$3:$F=A6),B6,2)
40
b
1
INDEX(FILTER($F$3:$G,$F$3:$F=A7),B7,2)
50
c
1
INDEX(FILTER($F$3:$G,$F$3:$F=A8),B8,2)
60
c
2
INDEX(FILTER($F$3:$G,$F$3:$F=A9),B9,2)
70
My attempt: Instead of using INDEX, I am trying to use VLOOKUP (which works well inside Arrayformulas)
ARRAYFORMULA(IF(G3:G9="",(VLOOKUP(F3:G,FILTER(A3:A=F3:F),2,B3:B))))
Data
data occurrences
INDEX FILTER
FORMULA RESULT
a
1
ARRAYFORMULA(IF(G3:G9="",(VLOOKUP(F3:G,FILTER(A3:A=F3:F),2,B3:B))))
FALSE
a
2
FALSE
a
3
FALSE
a
4
FALSE
b
1
FALSE
c
1
FALSE
c
2
FALSE
c
2
FALSE
Error: I get all rows "FALSE"
Any help?
MAP() function may work. Try-
=MAP(A3:A9,B3:B9,LAMBDA(x,y,INDEX(FILTER(G3:G,F3:F=x),y)))
To make it more dynamic for input columns try-
=MAP(A3:INDEX(A3:A,COUNTA(A3:A)),B3:INDEX(B3:B,COUNTA(B3:B)),LAMBDA(x,y,INDEX(FILTER(G3:G,F3:F=x),y)))
you can try this (helper column skipped)
=BYROW(BYROW(D2:D,LAMBDA(aixx,IF(aixx="",,aixx&COUNTIF(D2:aixx,aixx)))),LAMBDA(z,xlookup(z,BYROW(A2:INDEX(A:A,ROW(LOOKUP("zzz",A:A))),LAMBDA(aixx,aixx&COUNTIF(A2:aixx,aixx))),B2:INDEX(B:B,ROW(LOOKUP(2^99,B:B))),)))

Google Sheets: Query and list the last 5 values in a column if the column contains a number

I want to use Sparkline for a spreadsheet to show a trend of the last 5 soccer matches, where A and B are the goals, and C are the resulting points.
In column C, the points are only generated if values are entered for the goals and goals conceded, i.e. the columns are not empty.
A (Goals)
B (Conceded)
C (Points)
4
4
1
4
4
1
4
4
0
3
4
4
1
0
4
0
As you see, in row 3, column c is empty.
What I basically try to achieve, is to create a list where the last 5 entries which are not empty / null, are listed:
C (Points)
1
1
3
1
0
Is used this formula, but it somehow does not work
=query(J15:J114,"select * offset "&count(J15:J114)-5)
shorturl.at/gHPY9 (example result picture)
Tried to find a solution myself, but am stuck.
Best,
Feal
Use query() with a where clause, like this:
=query(
J15:J114,
"where J is not null
offset " & max(0, count(J15:J114) - 5),
0
)

Spreadsheet: Sum of dynamic number of rows

I have a table in my Google Spreadsheet that looks like this :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
4
day 1
8
5
day 2
7
6
day 3
9
7
total
Where I can have multiple "day rows", but I don't know how many. It can be only 1 like it can be 20 "day rows". And I want the "total row" to automatically do a SUM of the "day rows" above.
Result expected :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
15
4
day 1
8
5
day 2
7
6
day 3
9
7
total
24
Where B3 is equal to SUM(B1:B2) and B7 is equal to SUM(B4:B6)
I am trying to do that without the App Script, just using Spreadsheet native functions.
I think I should be using the SUM function or the Query function, but I don't know how to dynamically get the right range. Do you have any idea how to do that ?
Thank you
In your example, column B would be a mixture of constants and formulas. That would require a script to deposit the formulas. However with an extra column, you can avoid scripts. In C2 enter:
=if(A2<>"Total","",sum($B$1:$B1)-sum($C$1:C1))
and copy downwards:
Basically we add column B and subtract any previous Totals in column C.
Another approach is to place the following single array formula in C1:
=ArrayFormula(IF(A:A="",, SUMIF(IF(ROW(A:A),ROW(A:A)), "<="&ROW(A:A),B:B) - SUMIF(IF(ROW(A:A), ROW(A:A)),"<="& VLOOKUP(ROW(A:A)-1, FILTER(ROW(A:A), A:A="total"), 1, TRUE), B:B)))
If you only want to see the values for the "total" rows, change the opening
IF(A:A=""
to
IF(A:A<>"total"
The short version of how it works is that a sum is made of all values up to the current row in B:B, and from that is subtracted any values up to the last listing of the word "total" in A:A.
paste in each cell in B column where A column = total
=INDEX(SUM(IFERROR(1*INDIRECT(ADDRESS(MATCH(INDEX(
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()})-1, ROW()+1, 1),
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()}), 0), 2)&":"&
ADDRESS(ROW()-1, 2)), 0)))

Sum Offset from MS Excel to Google Spreadsheet

I've made an excel document from MS2013 (xlsx) that computes all numbers above it, because i want it to dynamically compute and adjust its own formula as i add more rows above it. But when i import this on google spreadsheets, the formula doesn't work anymore. here is the sample and formula
A B C D
1 3 3 2 2
2 4 3 4 5
3 5 6 4 3
4
5 12 12 10 10
the formula for A5 is =SUM(A1:OFFSET(A5,-1,0))
when i add 1 more row above A5 the formula adjusts accordingly to the formula's current position. What's the correct formula for google spreadsheet?
I propose you this formula (it's certainly not the better solution, nevertheless it's a solution):
=sum(indirect("A1:"&ADDRESS(ROW()-1;COLUMN())))
You can use this in your example:
=SUM(A1:A4)
If you start adding extra rows, then they will be automatically accounted for.

Sum of Hour and Time value in diffrent column in excel 2010

I have an Excel file which contains two columns for hours and minutes, like:
hr |min
---+---
7 | 2
10 | 16
9 | 12
I would like it to present in additional column as
07:02
10:16
09:12
How to do that in Excel 2010?
A B C
1 hr min hr:min
2 1 2
3 2 12
4 3 15
5 10 45
click on the cell C2 and put follwing formula at the formula bar and drag it for other rows.
=CONCATENATE(CONCATENATE(IF(A2 >9, A2, CONCATENATE("0",A2)),":"),CONCATENATE(IF(B2 >9, B2, CONCATENATE("0",B2))))
To get Sum of the of hr:min column
click on the cell where you want to display total and put follwing formula at the formula bar.
=CONCATENATE(CONCATENATE((SUM(A2:A5) + INT(SUM(B2:B5)/60)),":"),MOD(SUM(B2:B5),60))
Here you go
=SUM(TIME(A2,B2,0))

Resources