This question already has answers here:
ArrayFormula of Average on Infinite Truly Dynamic Range in Google Sheets
(6 answers)
Closed 6 months ago.
I have the following table structure
Name
Role
rank 1
rank 2
rank 3
rank 4
rank 5
rank 6
Average
Jon
Admin
5
6
7
8
8
9
Tomas
Accountant
3
2
2
9
3
3
Ellie
Admin
2
9
7
3
9
1
Sam
Sales
4
7
3
9
1
8
The actual table has circa 2k rows, and has a lot more columns, before I was using the following formula then dragging down.
=IF(B2 = "Admin", AVERAGE(C2,D2,F2), AVERAGE(C2,F2,G2,H2))
But this was really slow (especially as other sheets are doing something similar) almost rendering the sheet to be unusable.
Unsure how to convert the above formula into an array formula so I just need to enter one fomula for a cells.
I've tried
=ArrayFormula(IFERROR(IF(B2:B = "Admin", AVERAGE(C2:C,D2:D,F2:F), AVERAGE(C2:C,F2:F,G2:G,H2:H)), ""))
But I get the following result
Name
Role
rank 1
rank 2
rank 3
rank 4
rank 5
rank 6
Average
Jon
Admin
5
6
7
8
8
9
5.583333333
Tomas
Accountant
3
2
2
9
3
3
5.3125
Ellie
Admin
2
9
7
3
9
1
5.583333333
Sam
Sales
4
7
3
9
1
8
5.3125
When it should be
Name
Role
rank 1
rank 2
rank 3
rank 4
rank 5
rank 6
Average
Jon
Admin
5
6
7
8
8
9
6.333333333
Tomas
Accountant
3
2
2
9
3
3
4.5
Ellie
Admin
2
9
7
3
9
1
4.666666667
Sam
Sales
4
7
3
9
1
8
5.5
use:
=INDEX(IF(B2:B="Admin",
QUERY(SPLIT(FLATTEN(ROW(C2:C)&"×"&{C2:D, F2:F}), "×"),
"select avg(Col2)
group by Col1
label avg(Col2)''"),
QUERY(SPLIT(FLATTEN(ROW(C2:C)&"×"&{C2:C, F2:H}), "×"),
"select avg(Col2)
group by Col1
label avg(Col2)''")))
Related
I have 2 sheet2 on the same file:
the first collect the answers of different trial judge and the second should make the total
Like this:
First sheet
Name q1 q2 q3 total judge_id
Bob 1 5 8 14 1
Jeff 2 4 2 8 1
Bob 3 1 4 8 2
Bob 5 3 2 10 3
Jeff 6 1 8 15 3
Second sheet
judge_id 1 2 3 tot
Bob 14 8 15 37
Jeff 8 # 15 23
How can I sum only the row on a 'person' in particolar?
There is a fast way to do it without open Google Script?
try:
=ARRAYFORMULA({QUERY({A2:F},
"select Col1,sum(Col5) where Col1 is not null group by Col1
pivot Col6 label Col1'judge_id'"), {"tot"; MMULT(QUERY(QUERY({A2:F},
"select sum(Col5) where Col1 is not null group by Col1 pivot Col6"),
"offset 1", )*1, SEQUENCE(COUNTUNIQUE(F2:F), 1, 1, ))}})
Here's my take on it:
={
QUERY(A1:F,"SELECT A, SUM(E) WHERE A IS NOT NULL GROUP BY A PIVOT F LABEL A 'Judge ID'"),
QUERY(A1:F,"SELECT SUM(E) WHERE A IS NOT NULL GROUP BY A")
}
A B C
1 Timestamp Hours Worked Total Hours
2 1/2/2022 17:33:41 6
3 1/3/2022 19:59:41 2 January =
4 1/7/2022 13:20:51 1
5 1/9/2022 12:49:02 3 February =
6 1/15/2022 12:04:21 3
7 2/16/2022 15:58:10 9 March =
8 2/22/2022 11:57:31 3
9 2/24/2022 5:45:12 5
10 2/2/2022 17:33:41 4
11 2/3/2022 19:59:41 2
12 2/7/2022 13:20:51 1
13 3/9/2022 12:49:02 3
14 3/15/2022 12:04:28 3
15 3/16/2022 15:58:10 7
16 3/22/2022 11:57:31 3
17 3/24/2022 5:45:12 5
I would like to sum the hours by date/month. I can sum the hours by
column, =sum(b2:b). But how do I sum the hours in Column B by
date/month of column A?
In another post, a member referenced the 'Google Sheets function list'.
I have found that to be very helpful on other things I have been doing.
But I am still at a lose for this problem.
John
You could use the query function with SQL:
=QUERY({(data)}, "select sum(Col2) group by Col1 label Col1 'Date', Col2 'Sum'")
That would return a new table, and you can adjust it by changing the second parameter, representing the SQL string. You can view Google's docs for the query function here. In addition you can find their docs for the query language here.
The simplest solution, without any formula, is to build a pivot table.
use:
=ARRAYFORMULA(REGEXREPLACE(TO_TEXT(QUERY({TEXT(A2:A, "yyymm\×mmmm"), B2:B},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label sum(Col2)''")), "(.*×)", ))
I have a column like this:
A B C
1 Column
2 1
3 0
4 1
5 2
6 0
7 2
8 3
9 1
I want to be able to sum each pair of two rows with one or two formulas that I can drag down. So hard coded, my formulas would look like this:
A B C
1 Column
2 1 =SUM(A2:A3)
3 0 =SUM(A4:A5)
4 1 =SUM(A6:A7)
5 2 =SUM(A8:A9)
6 0
7 2
8 3
9 1
Thanks in advance.
Here is what I ended up doing. I added two reference columns then performed a SUMIFS() with another column matching every other reference column.
A B C D E
1 REFERENCE1 REFERENCE2 Column FORMULA REFMATCH
2 1 =ROUNDDOWN(A2) 1 =SUMIFS(C:C, B:B, E2) 1
3 1.5 =ROUNDDOWN(A3) 0 =SUMIFS(C:C, B:B, E3) 2
4 2 2 1 2 3
5 2.5 2 2 4 4
6 3 3 0
7 3.5 3 2
8 4 4 3
9 4.5 4 1
Try this:
=arrayformula( query( query( iferror( if( {1,1,0}, floor( mod(row(A:A)-{1,1},{10^99, 2}), {2,1} ), transpose( split( regexreplace( query( transpose( query( transpose(A2:A9 & char(9)), , 50000 ) ), , 50000 ), "\s+$", "" ), char(9) & " ", ) ) ) ), "select max(Col3) where Col3 is not null group by Col1 pivot Col2", 0 ), "select Col1 + Col2 offset 1 label Col1 + Col2 '' ", 0 ) )
This is an array formula that creates the whole result table in one go. It does not require helper columns.
Try this:
=ArrayFormula(ARRAY_CONSTRAIN(FILTER(A2:A,ISEVEN(ROW(A2:A))) + FILTER(A2:A,ISODD(ROW(A2:A))),ROUND(COUNTA(A2:A)/2),2))
This is an array formula, so it does not get dragged. That is, this one formula produces all results.
Simply put, this adds the values in all even rows to the values in all odd rows.
Since values are paired, ARRAY_CONSTRAIN just limits the return to half the rounded number of available values.
Could work adding a column "A" of pairs and putting this formula in the 3rd column =IF(A1=A2,"",SUMIF($A$1:$A$8,A1,$B$1:$B$8))
A B C
1 7 =IF(A1=A2,"",SUMIF($A$1:$A$8,A1,$B$1:$B$8))
1 8
2 9
2 34
3 2
3 4
4 5
4 6
drag down and should remain like this:
A B C
1 7
1 8 15
2 9
2 34 43
3 2
3 4 6
4 5
4 6 11
Isn't exactly what you want with just one formula, but it could work with one formula and one column added.
I have a Google sheets with the following layout
Key Points Category Done
1 4 A Yes
2 4 B
3 1 B
4 5 C Yes
5 7 D Yes
6 4 B
7 2 C Yes
I need a formula that can sum the points based on category if the Done is "yes". So the output should be
Points done Category
7 C
4 A
7 D
Whch formula can I use for this? (I don't want to use pivot table)
try:
=QUERY({A2:D}; "select sum(Col2),Col3 where Col4 = 'Yes' group by Col3 label sum(Col2)''")
I have 3 sheets that have the exact same format
Sheet1
A B C D
George 10 2 8
Nick 15 89 0
Mike 13 1 50
Lucas 9 -5 12
Sheet2
A B C D
Nick 1 9 5
Mike 1 10 6
George 11 22 5
Lucas 10 5 2
Panos 55 0 1
Sheet3
A B C D
Panos 0 9 1
George 1 2 5
Nick 7 2 1
Lucas 1 5 1
I want to query the range {'Sheet1'!A1:D5; 'Sheet2'!A1:D5; 'Sheet3'!A1:D5}
And get something like MAX(Col2:Col4) Group By Col1
Which would return something like:
George 22
Nick 89
Mike 50
Lucas 12
Panos 55
I tried:
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(Col2:Col4) Group by Col1 Label MAX(Col2:Col4) '' " ),2, FALSE)
and
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(MAX(Col2),MAX(Col3), MAX(Col4)) Group by Col1 " ),2, FALSE)
Both didn't work. Any ideas?
Please try:
=query(sort(transpose(query({Sheet1!A1:D5;Sheet2!A1:D5;Sheet3!A1:D5},"select max(Col2), max(Col3), max(Col4) pivot Col1"))),"select Col1, max(Col2) group by Col1 label(Col1) ''")
To sum up your question, It requires finding the MAX across the columns to the right as well as down. As such, QUERY does NOT have such 2D function.
So, Use a Helper column E&F in each sheet:
Max of B&C:
E2:
=ARRAYFORMULA(IF(B2:B>C2:C,B2:B,C2:C))
Max of B,C&D:
F2:
=ARRAYFORMULA(IF(D2:D>E2:E,D2:D,E2:E))
Now, Use Query:
Query:
=ARRAYFORMULA(QUERY({Sheet1!A2:F;Sheet2!A2:F;Sheet3!A2:F}, "Select Col1,max(Col5) where Col1 is not null group by Col1 order by max(Col5) desc"))
Notes:
Change ranges to suit
You could also simply use MAX for each row without the ARRAYFORMULA
Theoretically, For a single cell solution, You could enter this formula to find the max of 3 real numbers
Another approach perhaps a bit simpler but needing two queries
=sort(unique(({Sheet1!A1:A5;Sheet2!A1:A5;Sheet3!A1:A5})))
to get the names starting in (say) F2
Then this to get the maximum values for each name in (say) G2 and pulled down
max(query({Sheet1!A$1:D$5;Sheet2!A$1:D$5;Sheet3!A$1:D$5},"select max(Col2),max(Col3),max(Col4) where Col1='"&F2&"'"))