SUMIFs by only calculating unique values in another column - google-sheets

I currently have a table with five columns:
A = Campaign
B = Person
C = Opportunity Name
D = Total Cost of Campaign
E = Date
I'm trying to use =sumifs to calculate the amount in column D only if: (1) it matches the exact value in cell H2 to column A, (2) the date range, in column E, is greater than the value in cell I2, and (3) it removes duplicates based on value in column C (so you can't sum if value appears more than once).
Please refer to my data table (also attached) as reference:
Campaign Person Opportunity Name Total Cost of Campaign Date
A Bob Airbnb 5000 3/2/2017
B Jim Sony 10000 3/2/2017
B Jane Coca-Cola 10000 3/2/2017
C Jim Sony 200 3/2/2017
B Daniel Sony 10000 3/2/2017
B April Coca-Cola 10000 3/5/2017
How could I do this?
Thanks in advance for the help!

Try:
=SUM(
UNIQUE(
QUERY(A:E,"select C, D where A = '"&H2&"' and E > date '"&TEXT(H3,"YYYY-MM-DD")&"'")))
Query will cut first two conditions. Unique will remove duplicates:

Related

Filtering on multiple criteria in the same column in Google Sheets

I have one sheet that has IDs for which I'd like to pull information about from another sheet.
Sheet 1 with IDs:
Id
A
B
Sheet 2 with additional information:
Id
Amount
A
$500
A
$600
A
$700
B
$200
B
$300
B
$400
C
$30
C
$40
C
$50
I would like returned all information from Sheet 2 that matches all the IDs in Sheet 1. The result I want:
Id
Amount
A
$500
A
$600
A
$700
B
$200
B
$300
B
$400
I have tried using =FILTER(Sheet2!A:B,Sheet1!A2=Sheet2!A:A) but that only gets me the first ID:
Id
Amount
A
$500
A
$600
A
$700
I've played around with changing Sheet1!A2 in the filter formula to Sheet1!A:A but that throws an error. How can I get information for all IDs? Help!
Try FILTER() with COUNTIFS().
=FILTER(Sheet2!A2:B,INDEX(COUNTIFS(A2:A,Sheet2!A2:A)))
FILTER()
COUNTIFS()
You can try with FILTER and REGEXMATCH:
=FILTER(Sheet2!A:B, REGEXMATCH (Sheet2!A:A,TEXTJOIN("|",1,Sheet1!A:A)))

Google Sheets: Repeat values as rows based on associated numbers

I have a table in Sheets that has 2 columns: (1) Station (2) Number of people at Station:
Station Number of People at Station
A 1
B 2
C 1
D 4
I want to have a new column in excel populate with Station names repeating in it's own row based on number of people at station. The expected output would be below:
Station Allocation
A
B
B
C
D
D
D
D
Is there a way to dynamically have this final table change based on the number of people at station? So if someone was to use a google sheet and they change Station A to 2 people, then there will now be 2 rows with A instead of 1.
Try:
=arrayformula({"Values";query(flatten(if(B2:B<>"",split(rept(A2:A&"|",B2:B),"|"),)),"where Col1 is not null",1)})
Replace "|" with a character that is not used in your dataset.

Sheets: Count Row data Based on Key

Im trying to find a Row based on a value, and count the number of entries (Max 5) in that row.
A
B
C
D
E
F
G
1
John
2
2
5
4
2
Mary
1
3
1
6
7
=COUNTA(B1:GZ) will work if I knew the row for "John",
but im trying to get the row based on a value from another cell ...
Z
10
John
In this case Z10 pseudo: =COUNTA(Find Z10 in Col A, then count entries in Row starting at B to Z)
Any ideas ? Thanks.
Recommendation:
You can try this method
=COUNTA(QUERY(A1:Z, "Select * where A = '"&Z10&"'"))-1
Sample
Sample sheet:
John added on cell Z10
The recommended function added on cell Z11
Result: 4 was the result of COUNTA on the rows B:Z based on Column A that contains the value "John"
NOTE:
You may need to turn on Iterative calculation on your Spreadsheet settings.

How to compare data within one column in Google Spreadsheets

I need to calculate a column in google spreadsheet.
Column B is a price column (priceUSD). I want to be able to calculate if the price the following day is 5 % higher or more, then it should return a 1.
Otherwise a 0 (if price is less than 5% higher the following day)
I do not want to add more columns for this only using column D
(column A is a date column)
A B C D
date priceUSD Addres Over5
=if(B1*1,05>B2) then return 1
Maybe, in D3, something like:
=ArrayFormula(1*(B2:B900*1,05<B3:B900))

How to use QUERY in Sheets to find most recent grade for each student?

I have a spreadsheet containing a list of assessments for students. It is comprised of four columns:
A B C D
Student Standard Date Score
On another sheet I have a table containing a list of students in column A and a list of standards in Row 1.
I want to query the spreadsheet of assessments to return the score of the most recent assessment for the current student on the current standard. Currently I have this formula in cell K3:
=Query(Assessments!A:D,"select D where(A="&$A3&" and B="&K$1&") order by max(C) limit 1")
but it gives me this error:
Unable to parse query string for Function QUERY parameter 2: AGG_IN_ORDER_NOT_IN_SELECTMAX(C)
Edit:
I've gotten some great answers, but I guess I asked poorly. What I really need is the score from the most recent assessment. The results from JPV and pnuts have both given the date of the most recent assessment. Here is a stripped down version of the actual file: spreadsheet.
In the Students sheet I'm needing a formula in the Green cells that results in a number from 0 to 4 based on the data in the Assessments sheet.
This is why in the query I was trying to select D, but order by max(C).
I tweaked one of these formulas and got:
=iferror(query(A3:D20, "Select D where A = '"&G20&"' and B = '"&I20&"' order by C desc limit 1",0), "no data found")
I addition to the fine solution provided by pnuts (+1 for the sample data), here are some posibilities using query (check the green cells in this spreadsheet.
=query(A2:D20, "select A, MAX(C) GROUP BY A pivot B",1)
or
=query(A2:D20, "select A, B, MAX(C) GROUP BY A, B",1)
should create a table with the latest date per student, per standard.
In case you want to use cell references (where a cell holds a student name and another cell holds the standard), try:
=iferror(query(A3:D20, "Select A, B, C where A = '"&G20&"' and B = '"&I20&"' order by C desc limit 1",0), "no data found")
where G20 is student name and I20 is standard (change range to suit).
Does not use the query function but seems to "query the spreadsheet of assessments to return the most recent assessment for the current student on the current standard":
=iferror(max(filter(Assessments!$A$1:$D$99,Assessments!$A$1:$A$99=$A3,Assessments!$B$1:$B$99=K$1)),"")
Constructed data as example:
Student Standard Date Score
Bod5 C 2/2/2015 9
Bod6 B 1/1/2015 8
Bod7 C 7/7/2015 7
Bod8 A 9/9/2015 6
Bod1 B 3/3/2015 5
Bod2 C 4/4/2015 43
Bod3 B 6/6/2015 2
Bod4 C 1/1/2015 1
Bod1 A 1/1/2016 8
Bod1 A 2/2/2017 7
Bod1 A 1/1/2013 6
Bod1 A 1/1/2011 5
Bod9 A 9/9/2009 9
Bod9 B 1/1/2011 3
Bod9 C 3/3/2013 2
Bod9 A 10/10/2010 4
Bod9 B 11/1/2001 2
Bod9 C 4/4/2014 1
Output:

Resources