I have a table with the result of a test. The table is structured as follows:
student score_description score_value
Juan test 1 5
Peter
Brian test 2 8
Jose test3 10
I need to convert this into a kind of pivot table using only formulas. For this, I thought of using the INDEX & Match but it doesn't work. At the end, I should see something like this:
student test1 test2 test3
Juan 5
Peter
Brian 8
Jose 10
Thanks a lot!
Try
=QUERY(A:C,"select A,sum(C) where A is not null group by A pivot B ")
or
=QUERY(A:C,"select A,sum(C) where B is not null group by A pivot B ")
Related
I have data that arrives as so in a sheet from a google form. It's to manage pieces of our product that we send to a painter.
in/out model_1 model_2
-------------------------
in 10 0
out 5 0
in 10 10
in 2 5
out 2 12
I want something like so
model IN OUT
-------------------------
model_1 22 7
model_2 15 12
I managed to get the first column with a query with something along those lines
SELECT SUM(B), SUM(C) WHERE A="in"
Then I added a TRANSPOSE.
How to add to the query a second column where A="out" ?
This is the real query :
=TRANSPOSE(QUERY('Réponses au formulaire 2'!A1:W; "SELECT SUM(E), SUM(F), SUM(G), SUM(H), SUM(I), SUM(J), SUM(K), SUM(L), SUM(M), SUM(N), SUM(O), SUM(P), SUM(Q), SUM(R), SUM(S), SUM(T), SUM(U), SUM(V), SUM(W) WHERE D = 'DEPOT'";1))
Hope you understand what I mean. Maybe another approach is best?
But for now I'm kinda stuck but not really happy with my solution of adding a second query as it add a column of labels sum_a sum_b....
Would this do it?
=TRANSPOSE(QUERY('Réponses au formulaire 2'!A1:W; "SELECT D,SUM(E), SUM(F), SUM(G), SUM(H), SUM(I), SUM(J), SUM(K), SUM(L), SUM(M), SUM(N), SUM(O), SUM(P), SUM(Q), SUM(R), SUM(S), SUM(T), SUM(U), SUM(V), SUM(W) WHERE D = 'DEPOT' OR D = '2nd Option' group by D";1))
Change 2nd Option with your desired value
you could try this formula:
=transpose({{B1:G1};BYCOL(FILTER(B2:G,A2:A="in"),lambda(row,sum(row)));BYCOL(FILTER(B2:G,A2:A="out"),lambda(row,sum(row)))})
Feels like this may be a basic, but I cannot find a way to do this with sumifs.
I've got four columns in one table, representing the workload of an employee like this:
Job
Employee # 1
Employee # 2
Workload
Job 1
Bob
Jane
5
Job 2
Bob
2
Job 3
Jane
Susan
3
Job 4
Susan
2
I'd like to output total workflow results to a second sheet for each employee based on a specialized formula. In English, the forumla would be:
Calculate the total workload for each employee.
- For each job that includes that includes employee named "X" and no assigned teammate, use the job's corresponding workload value.
- For each job that includes that includes employee named "X" and has an assigned teammate, reduce the corresponding workload value by 50%.
So with the given table above, I'd want an output like this:
Employee Name
Workload
Bob
4.5
Jane
4
Susan
3.5
Math:
Bob = ((job_1 / 2) + job_2)
Jane = ((job_1 / 2) + (job_3 / 2))
Susan = ((job_3 / 2) + job_4)
Does anyone know how I can accomplish this?
Functions like sumifs seem to only let me set criteria to sum or not sum a value. But I cannot find a clear way to sum only 50% of a value based on a condition in a separate column.
=LAMBDA(name,SUMIFS(D2:D5,B2:B5,name,C2:C5,"")+SUMIFS(D2:D5,B2:B5,name,C2:C5,"<>")/2+SUMIFS(D2:D5,C2:C5,name)/2)("Bob")
The math is
SUM D, if B is Bob and C is empty and
SUM half of D if B is Bob and C is not empty and
SUM half of D, if C is Bob.
Or the same logic via query:
=QUERY(
{
QUERY(B1:D5,"Select B,sum(D) where C is null group by B");
QUERY(B1:D5,"Select C,sum(D)/2 where C is not null group by C");
QUERY(B1:D5,"Select B,sum(D)/2 where C is not null group by B")
},
"Select Col1, sum(Col2) where not Col1 contains 'Employee' group by Col1"
)
However, note that we're assuming title contains Employee and no other names contain Employee.
Employee # 1
sum sum Workload
Bob
4.5
Jane
4(Incorrect in the question)
Susan
3.5
Use this formula
=ArrayFormula({ "Employee Name", "Workload";
QUERY(
QUERY({LAMBDA(a,b,c,d,k, {b,a,{d/k};c,a,{d/k}} )
(A2:A,B2:B,C2:C,D2:D,
BYROW(B2:C, LAMBDA(c, IF(COUNTA(c)=0,,IF(COUNTA(c)=1,1,2)))))},
"Select (Col1),sum(Col3) Group by Col1" ,0), "Where Col1 <> '' ",0)})
Used formulas help
ARRAYFORMULA - QUERY - LAMBDA - BYROW - IF - COUNTA - SUM
Would deeply appreciate it if anyone could help me with this.
Overview
In a google sheet I have the following grid:
School A
School B
School C
Tim
x
x
John
Martin
x
x
Jack
x
The Rows are Names of people who cater to certain schools. The value 'x' in the cell simply signifies the relation. So Tim caters to School A & School C and similarly Jack only caters to School C.
Note: The cells are either empty or contain that 'x'. Thought that might help. We don't really need to look for 'x' just a non-empty cell.
Question
I have another table like follows, where I have a School column listing all the schools in rows. I would like to create a formula to use the table above and return a concatenated string listing all the people catering to that school.
School
People
School A
Tim, Martin
School B
Martin
School C
Tim, Jack
use:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(FLATTEN(
IF(B2:D="",,B1:D1&"♠♦"&A2:A&",♦"&A2:A)), "♦"),
"select Col1,max(Col2) where Col2 is not nUll group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), "♠")), ",$", ))
or:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(
{B1:D1&"♦"; IF(B2:D="",,A2:A&",")},,9^9)), "♦")), ",$", ))
Was curious why Formula 2 (below) doesn't work, i.e. returns just a zero and not an array whereas Formula 1 works (below). The argument construction seems is similar.
DM:DM is list of employers. (not unique employers, i.e. Bob post several jobs)
DW:DW is # of positions offered for a particular job.
DU:DU is type of job.
DM DW DU
Bob 3 Sales
Alice 10 Cashier
Mike 4 Clerk
Bob 1 Sales
I think the issue is the way I am using the "Unique" function nested inside countifs vs. sumifs and wrapping this inside an arrayformula. In Formula 1, the array returns number of job posts for unique employer, and so Bob 2, Alice 1, Mike 1. What I was attempting in Formula 2 was Bob 4, Alice 10, Mike 4. I could accomplish this by separating multiple columns and functions but I wondered if anyone knew of an elegant way to do this using arrayformula so I have it in one column. Thanks and I hope this question was clear.
Formula 1
=arrayformula(countifs('Data (QC)'!DM:DM,UNIQUE('Data (QC)'!DM:DM),'Data (QC)'!DU:DU,"Shop Sales Assistant"))
Formula 2
=arrayformula(sumifs('Data (QC)'!DW:DW,'Data (QC)'!DM:DM,unique('Data (QC)'!DM:DM),'Data (QC)'!DU:DU,"Shop Sales Assistant"))
=arrayformula ( unique ({filter( Log!M2:M, Log!M2:M<>"" ), sumif ( filter ( Log!M2:M, Log!M2:M<>"" ), "=" & filter ( Log!M2:M, Log!M2:M<>"" ), Log!W2:W )}))
try:
=QUERY(A2:C, "select A,sum(B) where A !='' group by A label sum(B)''", 0)
and for count:
=QUERY(A2:C, "select A,count(B) where A !='' group by A label count(B)''", 0)
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&"'"))