Summing a column based on multiple data validation reference cells in Google Sheets - excel

I need to be able to sum the total payout amount given that there are multiple entries for the same user. In addition, I have a dropdown data validation reference cell that should show a smaller total sum based on payout_amount.
For example, total sum is 1,270. But if I am just looking at payout_amount for loss_type = 'Theft', the sum is 750.
How would I do this in Google sheets? How would I do this for multiple criteria (multiple dropdown data validation)?
user_id.
loss_type.
payout_amount
1
Theft
500
2
Theft
250
3
Liquid Damage
180
3
Liquid Damage
180
4
Liquid Damage
225
4
Cracked Screen
225
4
Cracked Screen
225
5
Battery Malfunction
115
5
Battery Malfunction
115
5
Battery Malfunction
115

You need SUMIFS() function for multiple criteria. Try below formula-
=SUMIFS(C2:C11,B2:B11,D2)
You can add more criteria for more dropdown value like
=SUMIFS(C2:C11,B2:B11,D2,A2:A11,E2)

Try QUERY.
=query(B1:C,"select B, sum(C) where B is not null group by B",1)
It's just one short formula and works for the whole range.

SUMIFS and UNIQUE is highly effective for your case.
Create dropdown from all items of loss_type. Try formula UNIQUE(B2:B) on cell H2 to get the list of all loss_type.
Create dropdown on E2.
Select E2 > Go to Data > Data Validation > Criteria (List from range) > Select H2:H
Then, use SUMIFS with the dropdown value as criteria on F2. Try the formula below -
=SUMIFS(C:C, B:B, E2)
This should automatically provide you with a total sum payout, once you select your required value in E2.

Related

Vlookup and sum all instances of the matching lookup

this is probably an extremely basic problem but I can't figure a way to do this within Excel.
I have a list of values IDs from a regional sales manager,
he wants to see if his figures have been inputted into the monthly report and are reporting correctly.
However, as he sells by region and we report by product we have multiple instances of his ID by Product
so our monthly report.. for example
ID Value
1 16,999
1 22,521
3 400
3 221
5 71
6 22,000
So he has provided me with a list of IDs
1
2
3
4
5
6
and wants a list with its total revenue not just the first match up.
Is an excel limitation or is there a way to do this?
You can use a SUMIF formula. Basically you give it the column to check the value of, then you give it the expected value and finally the colum to sum.
Option 1 (whole range)
=SUMIF(A:A, 1, B:B)
Option 2 (defined range)
=SUMIF(A1:A7, 1, B1:B7)
Option 3 (Using excel table)
=SUMIF([Id], 1, [Value])
For more details please refer to: https://support.office.com/en-ie/article/sumif-function-169b8c99-c05c-4483-a712-1697a653039b
Is this what you're looking for?
=SUMPRODUCT((A1:A5=1)*B1:B5)
Taken from here: Sum values from multiple rows using vlookup or index/match functions
How it works:
An array formula is used to create an array of numbers that gets passed to the SUMPRODUCT formula.
The array formula processes A1 and B1 together, then A2 and B2 and so on... if A1 is equal to 1, B1 is added to the array.

To filter multiple columns with a condition on the results

I am trying to find a way of highlighting a result with multiple conditions. I have no knowledge of pivot tables. I would rather use a formula or macros. The table is organised by Dealer.
Acc NAME Add Dealer Total
68687 Sara 11 Wood 111A 0
68687 Sara 11 Wood 111A 0
32187 Sara 11 Wood 111A 0
12345 Tom 10 Main 7878C 2
12345 Tom 10 Main 7878C 2
54321 Tom 10 Main 7878C 2
My table is similar to the one above. I want to select where the Total is greater than 0 & for each Dealer each unique Account number with the lowest Account number highlighted somehow.
So the results I want for the table above would be: Dealer 7878C, Accounts 12345, 54321.
12345 being the lower of the two, it is highlighted.
I don't mind copying the results onto another sheet, as I don't want to remove any data from the sheet. I started by just filtering the Totals for >0 and I was thinking of trying to filter for unique values in Account but its the next step that I am stuck on. A countifs formula?
The sheet is quite large and I'm just not sure which is the best way to try and do it.
Thanks for any help.
There's a nice but complicated way to do it.
With your original data:
With changed data:
As you can see I've placed your data in A1:E7.
I use two array formulas, one for the Dealer in G2:G5 and one for the Accounts H2:N5. The Dealer formula is vertical, and the Accounts formula is horizontal.
For the dealers put this array formula in G2 (press Ctrl+Shift+Enter to enter it):
=IFERROR(INDEX($D$2:$D$7,SMALL(IF(($E$2:$E$7>0)*(COUNTIF($G$1:$G1,$D$2:$D$7)=0),ROW($D$2:$D$7)-1),ROW($G$1:$G1))),"")
Now copy G2 down to G3:G5 to get the rest of the relevant dealers.
For the accounts put this array formula in H2:
=IFERROR(SMALL(IF(($D$2:$D$7=$G2)*(COUNTIF($G2:G2,$A$2:$A$7)=0),$A$2:$A$7),1),"")
Now copy H2 to the right, I2:N2, and down to H3:N5.
To make the first accounts bold I simply make the H column formatted as Bold.
You can copy these formulas farther as needed. Note that the locations are important. If you want to place the formulas elsewhere you'll need to change the references accordingly.
Formulas explained
What these formulas do is check for your conditions, and then get the smallest value that hasn't been retrieved yet, in the upper / left most cells.
The two formulas are mostly the same, apart from the fact that in the account numbers we can use the actual numbers, and with the dealer we use the row number instead.
The dealer formula from the inside out:
The conditions are set in the IF part of the formula, with a multiplier * as a logical AND (TRUE*TRUE=TRUE FALSE*TRUE=FALSE).
The first condition in IF(($E$2:$E$7>0)*(COUNTIF($G$1:$G1,$D$2:$D$7)=0),... checks for the row's Total value to be greater than zero, the second condition checks that the dealer is not already present in the G column. The second condition is irrelevant in the first cell, but in the second cell G3 it becomes COUNTIF($G$1:$G2,... which returns more than 0 if the dealer already exists, and evaluate to FALSE.
If the conditions are met the IF returns the dealer's index by using its row minus 1 ROW($D$2:$D$7)-1, which returns 1 for the first etc. as the starting row is 2. Otherwise it returns FALSE which is ignored.
The SMALL function returns the k-th smallest item. It ignores the FALSE items, and in our case returns the k-th smallest index that meets the conditions (Total>0 and not already present in the results). SMALL(...,ROW($G$1:$G1) in the first cell return the first item. ROW($G$1:$G2) in the second cell G3 evaluates to 2 and returns the second smallest item, and so forth.
The INDEX function simply returns the dealer from the data according to the index.
And finally, the IFERROR is there only to hide the errors when the end of the results is reached.
based on your sample data and assuming a header row in row 1 and the left column being column A.
=COUNTIF($A$2:A2,A2)
place that in F2 and copy down. Then do a filter on the helper column =1

Automatically working out the average of filtered results

I have a spreadsheet where column P has a score between 1-6
The cell O4 has the following formula: =AVERAGEIFS(P8:P5000,P8:P5000,"<>6",P8:P5000,"<>0")
This formula searches for the average of the score in column P excluding 6, blanks and 0
Column O has staff names e.g John, Mark, Tim.......
What i want to do is for Cell O4 to automatically calculate the average of the figures shown in column P after i have used the filter function to show only results of a selected staff member.
I was hoping excel might be able to do this automatically however cell O4 appears to still be showing the average of the whole column P regardless of whether i have filtered or not.
I was given the formula below on another forum but it seems to be giving slightly wrong results albeit only by a small amount but i need to have the results exact if possible. Any help appreciated.
=SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(9,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))/SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(2,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))
Maybe
{=AVERAGE(IF((P8:P5000<>6)*(P8:P5000<>0)*SUBTOTAL(103,INDIRECT("O"&ROW(8:5000))),P8:P5000))}
will do what you want. Assuming the Filter is on column O.
The 103 in SUBTOTAL will also exclude if rows are manually hidden. If this ist unwanted and it should only exclude hidden rows, if filtered, then use 3 instead.
This is an array formula. Input it into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter] to create the array formula.
I would create a separate table in a new sheet with all unique staff members and then perform the calculation. This way, you can quickly compare values for all staff just by scanning the table instead of having to constantly update the filter to see the values for potentially dozens or hundreds of staff. You would add the staff name range and criteria to your AVERAGEIFS formula.
For your example:
Sheet 2
A B
--- ---
1 | Staff Average
2 | Bob =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A2,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
3 | Mary =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A3,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
4 | Joe =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A4,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")

List all items less than average

Suppose we have following data
prices
leptop 30
pc 29
table 10
house 15
car 25
train 32
pen 45
dog 33
cat 17
TV 8
I have calculated average of these prices avg==AVERAGE(D3:D12) where D3:D12 are price columns. Now I want to choose these items or list items which has price less than average for example, I know there is function if, but how can I use it together to list all data, which satisfies the if condition?
Are you trying to list the prices that are less than the average all in the same cell?
If you're just trying to indicate whether they are or not next to the column, you could use: =IF(D3 < AVERAGE($D$3:$D$12), "Less Than", "Greater or Equal")
Edit:
http://i.imgur.com/SRTfvJe.png
Ok, to get the result you want (see image) then you need to use the following formulas (this assumes these formulas are in column F).
The first row in the column should be: =IF(B3 < AVERAGE($B$3:$B$6), A3, "") where B3 is the data and A3 is the name.
And all the other rows should be: =IF(B4 < AVERAGE($B$3:$B$6), IF(F3="", A4, F3 & ", " & A4), F3) where B4 is the data and A4 is the name.
This is how you could do with with Advanced Filter. Set-up your excel sheet as follows, and enter the formulas appropriately:
Then, go to Advanced Filter:
You will get:
In E3 and copied down:
=IF(D3<AVERAGE(D$3:D$12),C3,"")
will give a list (admittedly with spaces) if the names are in ColumnC. (Guessing that 'continue' does not mean the same cell.)
Does a filter work for your needs? If I go to the "data" tab in Excel 2010, highlight the data, and click "Filter", I can filter on items "below average" in the price column.

How to get uniques in column A and totals from column B?

I have a spreadsheet that looks like this:
A B
DeptA 10
DeptB 5
DeptA 5
DeptA 10
DeptC 5
DeptB 10
DeptA 20
DeptB 5
I'm trying to get a list of the unique values in A, and then the total in B for each unique value. The output I'm looking for is this, which can go in columns C/D (or wherever, doesn't matter)
DeptA 45
DeptB 20
DeptC 5
I know I can pull the uniques in A and place them in C with the following array formula:
=INDEX($A$2:$A$8, MATCH(0, COUNTIF($C$1:C1, $A$2:$A$8), 0))
How to list the column B totals along with it?
No formula is necessary.
For example, uniques may be obtained (avoiding COUNTIF, INDEX and MATCH) with Data > Sort & Filter – Advanced , Copy to another location selected, Unique records only checked and Copy to: set to C1 (though my version is a bit temperamental and at present also requires deleting C1 and sorting).
But with sorting (select A:B, Data > Sort & Filter – AZ) then subtotal can be used (insert a new row as Row1, select A:B Data > Outline – Subtotal, OK , OK [defaults are probably as required: At each change in: (Column A), Use function: Sum, Add subtotal to: (Column B), Replace current subtotals, Summary below data] then click on small ‘2’ at the top left.
Grand Total is a bonus.
You might want to use the DSUM Function as it's less work than pivoting.
EDIT: Corrected URL
You can keep your current construct and do a sumif or sumifs (they have different order of the arguments) in column D based on column C that sums column B.
Alternatively you can use a pivot table to get the complete result for you. Note however that a pivot requires manual refreshing, where the formulas will auto update when calculation is set to automatic

Resources