Google Sheets - Sum unique rows in - google-sheets

In Google Sheets, I am trying to sum all values of a unique pair of rows and sort, for example:
Input:
Name -|- Last -|- Expenses
-=-=-=-=-=-=-=-=-=-=-=-
Bruce Wayne 100
Jack Napier 75
Bruce Wayne 50
Jack Napier 5
Selina Kyle 90
Output:
Name -|- Last -|- Expenses
-=-=-=-=-=-=-=-=-=-=-=-
Bruce Wayne 150
Selina Kyle 90
Jack Napier 80

I think this is what you want:
=query(A1:C6,"select A, B, sum(C) group by B, A
order by sum(C) desc, B, A
label sum(C) 'Expenses' ",1)
Here is a sample table:
https://docs.google.com/spreadsheets/d/1WeQZ3U8ZGziQiDZUoJbvF4cwFif16oePTq8jlICvL88/edit?usp=sharing
This sorts the records descending by amount, plus alphabetically by Last then First name.
Let us know if this doesn't answer your question.
Good luck.

Related

How to calculate a sum conditionally based on the values of two other columns

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

How to extract unique rows based on a criteria across different sheets on Google Sheets

I have a main sheet with a lot of data but here it is simplified:
Manager
Employee
Project
Date
John
James
Pineapple
1/1/2021
John
James
Banana
1/1/2021
Alex
Robert
Apple
1/1/2021
Sally
Mindy
Kiwi
2/1/2021
Sally
Mindy
Orange
1/1/2021
Sally
Matthew
Tomato
2/30/2021
Sally
Mindy
Grape
1/1/2021
John
Vlad
Orange
2/30/2021
I tried using a formula that looks like this:
=ARRAYFORMULA(INDEX($B$2:$B,SMALL(IF($A$2:$A=B$1,ROW($A$2:$A)-MIN(ROW($A$2:$A))+1,""),ROW(B2))))
However it's not working.
I got the =UNIQUE() for each person from column A:
UNIQUE
John
Alex
Sally
I transpose this into their own columns:
John
Alex
Sally
and then I want a formula under each name that will go through the range that I specify
John
=UNIQUE() for column B "Employee" based on the criteria "John" in column A
=COUNTIF()
James
2
Vlad
1
And this would be useful to figure out the projects based on the criteria of column A "Manager"
John
=UNIQUE() Column C "Project"
=COUNTIF()
Pineapple
1
Banana
1
Orange
1
What's the best way of organizing this?
try:
=QUERY({A2:C}, "select Col3,count(Col2) where Col3 is not null group by Col3 pivot Col1")

QUERY: sum two columns and order by one in Google Sheets

I have the following data set:
Country Points Bonus_Points
---------------------------------------
United States 1 50
Brazil 3 50
France 7 30
United States 2 25
And now would like to query that data set and create a list with the following outcome where bonus points and points get summed up and the list is getting ordered by bonus points.
Country Points Bonus_Points
---------------------------------------
United States 3 75
Brazil 3 50
France 7 30
With
=QUERY(A1:C,"select A, B, sum(C) group by A, B order by sum(C) desc", 1)
I'm able to sum one column but somehow unable to manage to get the sum for B/points as well.
Any ideas?
See if this helps
=QUERY(A1:C,"select A, sum(B), sum(C) group by A order by sum(C) desc label sum(B) 'Points', sum(C) 'Bonus_Points'", 1)

Google Sheets filter formula get specific columns, plus between two dates

I am building somewhat of an invoice report tool where I would like to pull all of Client X's orders between the dates set in A1 and A2, but I only need 6 of the 35 columns.
So far I am able to use the =filter formula with ease but I get all the columns of course, and I have no idea how to only filter based on the dates in A1 and A2.
If my sample data is below, I want to be able to pull all records for Client 1, between the dates set in A1 and A2 and only show Col1, Col3, and Col 6 in my "report"
Row Col1 Col2 Col3 Col4 Col5 Col6
1 Client 1 $45.00 01/15/2016 123 Main Street 404-989-9999 John
2 Client 1 $75.00 01/17/2016 123 Main Street 404-989-9999 John
3 Client 3 $15.00 01/18/2016 456 Park Street 404-989-9999 Sue
4 Client 4 $35.00 01/18/2016 111 East Street 404-989-9999 Chris
5 Client 5 $95.00 01/19/2016 789 North Street 404-989-9999 Tim
6 Client 3 $65.00 01/20/2016 456 Park Street 404-989-9999 Sue
7 Client 3 $25.00 01/21/2016 456 Park Street 404-989-9999 Sue
8 Client 1 $45.00 01/22/2016 123 Main Street 404-989-9999 John
One way to achieve that would be the use of query()
=query(A2:F, "select A, C, F where A='Client 1' and C >= date'"&text(A1, "yyyy-mm-dd")&"' and C <= date '"&text(B1, "yyyy-mm-dd")&"' " ,0)
Change ranges to suit.
Another way (with filter) would look something like this:
=filter({A2:A, C2:C, F2:F}, A2:A="Client 1", C2:C >= A1, C2:C <= B1)
I hope that helps ?

How to create a listing of unique names from a list

I have a list of names in column A and numbers (1-4) in Column B.
I need a formula to extract the names to Columns D, E, F, etc., where if multiple names have the same number (1-4) each name would appear in its own column.
Have This Need this result
Column
A B C D E F
greg 1 3 Tim
hank 2 2 Hank Mike
mike 2 1 Greg
tim 3
If C1 has '3', then the following will give you all names that have 3 in column B
=transpose(filter(A:A,B:B=c1))

Resources