Google Spreadsheet SUMIFs equivalent - google-sheets

I need a SUMIFs equivelent in google spreadsheet. It only has SUMIF, no IFS.
here is my data:
# Salesman Term (Month) Amount
1 Bob 1 1,717.09
2 John 1 634.67
3 Bob 1 50.00
4 Bob 1 1,336.66
5 Bob 1 0.00
6 Bob 1 55.00
7 Bob 300 23,803.97
8 Bob 300 24,483.91
9 Bob 300 20,010.03
10 Bob 300 41,191.62
11 Bob 300 40,493.14
12 Bob 300 10,014.01
13 John 1 100.00
13 John 100 100.00
I want to add everything that BOB sold that the term is equal to or less then 100. I also want to SUM everything that bob sold that the term is greater then 100. Same for John.

You need to use the FILTER function combined with the SUMfunction. In your example with Bob, your function would be like (assuming your data columns is from A to C):
=SUM(FILTER(C:C;A:A="Bob";B:B<=100))

The new Google Spreadsheet, now has the SUMIFS function available.
You can use the following formula:
=SUMIFS(F1:F14,D1:D14, "=Bob",F1:F14, ">=100",E1:E14, "<100")
If you want to perform the calculation for John as well, I can recommend the following:
=QUERY(D1:F14, "SELECT D, SUM(F) WHERE E<100 AND F>=100 GROUP BY D LABEL D 'Who', SUM(F) 'Total'")
See example file I created: SUMIFS on DATA

Related

Google spreadsheet query multiple columns with a count column

I have a table like this:
Animal ID eye color
-------------------------
Rabbit 90 blue
Rabbit 90 brown
Cat 91 blue
Cat 91 green
Squirrel 92 brown
What I have is
=QUERY(A2:C6;"select A,count(A) group by A")
which returns two columns. Now I want to add the ID column to it.
The desired outcome basically is:
Animal ID Count
----------------------
Cat 91 2
Rabbit 90 2
Squirrel 92 1
I realize I can do a
=QUERY(A2:C6;"select A,B ")
But can't combine that with a count on A nor a count on B.
Is there some not too complicated way to do that?
If the same animal has the same ID, you can group by both:
=QUERY(A2:C6,"select A,B,count(A) group by A,B")
or choose max or min or avg value of ID per group:
=QUERY(A2:C6,"select A,min(B),count(A) group by A")

How to count occurrence in previous rows based on two columns value

I'm trying to count the number of occurrence in previous rows based on two conditional values using Google Sheet.
Let say this is my table :
Row A
Row B
Row C
Row D
1
John
Smith
2
Marty
Butler
3
John
Herbert
4
John
Smith
5
Philip
Rand
6
John
Smith
7
Marty
Butler
Is there a formula that exist that can count those occurrences. The idea is that when I log a new name, if Row B and C already exist it increase the value in Row D by 1 so I would know that it is the nth entry under that name. In my example, Row D would looks like this:
Row A
Row B
Row C
Row D
1
John
Smith
1
2
Marty
Butler
1
3
John
Herbert
1
4
John
Smith
2
5
Philip
Rand
1
6
John
Smith
3
7
Marty
Butler
2
Delete everything in Column D (including the header) and place the following in D1:
=ArrayFormula({"Header";IF(B2:B="",,COUNTIFS(B2:B&C2:C,B2:B&C2:C,ROW(A2:A),"<="&ROW(A2:A)))})
The "Header" text can be edited as you like.
The COUNTIFS reads, in plain English, "Count how many times this first and last name combination has occurred within only the rows up to the current row."

how to make a new table from an existing table and add new column in spreadsheet

I want to Ask about spreadsheet or google-sheets formula. I have a data that looks like this:
A B C D
------------------------------------------------
1 | UserId fruitType media PriceStatus
2 | 3 Apple Bag Paid
3 | 7 Banana Bag Paid
4 | 7 Apple Bag Paid
5 | 43 Banana Bag Paid
6 | 43 Apple Bag FREE
7 | 43 Apple Cart Credit
Note:
My data only consist of 2 type of fruit : Apple and banana
2 type of media : Bag and Cart
3 Type of PriceStatus : Paid, Credit, & Free
As you can see the column is the same as the one in spreadsheet that I give value A-D and the row as 1-7, My plan is to make the sheets look like this:
UserId Apple Banana
3 1 0
7 1 1
43 2 1
is it possible to make a new table like this in spreadsheet? I tried using VLOOKUP but still failed to implement it, can someone help me with this?
try:
=QUERY(A1:D, "select A,count(A) where A is not null group by A pivot B", 1)

Find total price given the quantity for each month and the rate for each month

Question: What is the best formula to add quantity multiplied by different rates based on dates?
Example:
Rate 1: 1/1/2017 - 4/30/2017 $5
Rate 2: 5/1/2017 - 6/30/2017 $6
Rate 3: 7/1/2017 - 12/31/2017 $7
Apples per month
Jan: 10
Feb: 30
Mar: 10
Apr: 50
May: 40
Jun: 70
Jul: 80
Aug: 40
Sep: 20
Oct: 10
Nov: 40
Dec: 100
The date is 5/9/2017. The formula would find that the date starts with Rate 2 and ends with Rate 3.
So, the calculation would be:
((40+70)*$6) +((80+40+20+10+40+100) *$7 )) = $2,690.00
What is the best formula to calculate this way? Use SUMPRODUCT? I am baffled...
Format a lookup table for rates, in which the first column is the date on which each rate goes into effect:
+----------+---+
| 1/1/2017 | 5 |
| 5/1/2017 | 6 |
| 7/1/2017 | 7 |
+----------+---+
Let's say the above is A1:B3. Now you can lookup the rate for any date (say a date is in C9) with
=vlookup(C9, A1:B3, 2, True)
Here vlookup searches for the date in the first column and returns the value from the second column for the nearest match that is less than or equal to the search key.
Then you can use sumproduct like this:
=sumproduct(D9:D15, arrayformula(vlookup(C9:C15, A1:B3, 2, True))
Here the rate is looked up for each date in the range C9:C15 (so those should be the first day of each month).
Finally, you want to do all of this, given a date like 5/9/2017. Suppose this date is in E1. Let's make 1 there. Say, in F1:
=date(2017, month(E1), 1)
Then filter the array of dates/amounts by the condition that the date is at least F1: filter(C:C, C >= F1). The final result will be like
=sumproduct(filter(D:D, C:C >= F1), arrayformula(vlookup(filter(C:C, C >= F1), A1:B3, 2, True))

Formula to condtionally sum an array of values from one sheet to give totals on another

I have two sheets, connected by ID, which contain details of events and charges.
Sheet1 (breakdown of charges):
[Oh, just discovered I'm not allowed to include screen shots. I apparently need 10 reputation points. Not sure how to show you my spreadsheet now...]
ID DBF PCC Extras
1 200
1 100
3 200
4 350
4 250
4 75
4 25
7 100
[Sorry this will probably look horrible, I can't figure out how to include a spreadseet snippet without using an image. I had 3 imaage all prepared ready.]
Sheet2 (indentification and summary information):
ID Type Name
3 MON Edwards
7 REC Smith
4 WDG Jones
1 FNL West
8 WDG Richards
9 WDG Morrison
11 INT Gray
I am trying to add three additional columns to sheet 2 so that it shows a summary of the charges for each event. I would the charges information to update automatically in sheet2 as detail is added to sheet 1.
The resulting sheet2 will look like this:
ID Type Name DBF PCC Extras
3 MON Edwards 200
7 REC Smith 100
4 WDG Jones 350 250 100
1 FNL West 100 200
8 WDG Richards
9 WDG Morrison
11 INT Gray
As data for ID 8, 9 and 11 is added to sheet1, the summations should automatically appear in sheet2.
I have been trying to create an array formula to put in sheet2:B2, something like this:
=QUERY('Log Items'!A:F, "select sum(C), sum(D), sum(E), sum(F) where A="&A:A, 0)
This produces the correct result for ID 1 but it stops there and I'm not sure why. Also, despite my 0 as the third parameter, the header row is output.
I tried encapsulating the above in an ARRAYFORMULA but get a parse error.
I have also tried various combinations of ARRAYFORMULA, SUM and IF but not got anything that works. For example:
=ARRAYFORMULA(SUM(IF('Log Items'!A:A=A:A,'Log Items'!C:E,0)))
This gives #N/A "argument out of range", which I don't understand.
Although I've been working with Excel for a while, I'm really new to Google's Array formulas but have mananged to use them successfully in other parts of my spreadsheet and found them really powerful.
If anyone could help me with this, I would be very grateful.
In Sheet2!D2:
=ARRAYFORMULA(IF(A2:A,MMULT(N(A2:A=TRANSPOSE('Log Items'!A2:A)),N('Log Items'!B2:D)),))
Note: the N() functions have become necessary with different coercion behaviour in the new version of Sheets. They can be omitted in the classic version.
MMULT usage

Resources