What im trying to do is to take an average of a set of numbers that are next to a certain number in the next column.... this is going to be hard to explain![]()
Basically.... in one column i will have either a 0, 1, 2 or 3. and this could be listed down like this (these are priorities):
and what i need to do is to take an average of the value of the cell next to a specific number.... for example:2 3 1 1 2 2 0 3 2 0
So i would have a formula for each of the priorities in a cell that would average the numbers to the right of that priority...2 5 3 6 1 16 1 8 2 10 2 12 0 15 3 3 2 30 0 9
So for example... the average of all priority 2's should be 10+12+30/3 = 17.333. ok now for the twist.....
I may have a 0 value in a cell next to a priority... i do not want this to be averaged. This is my main problem. I have been using a combination of SUMIF functions and COUNTIF functions but cant get anything to work. Here is where i have got so far (e.g. for a priority 2):
- This seems fine.... this is summing the amounts next to a priority... its the next bit thats tricky... i now need to divide this by the number of cells with a value in it (>0) next to that priority (2)=SUMIF(A1:A9,"=2",B1:B9)
I can do thebut i only need the values next to 2. Can anyone help?COUNTIF(B1:B9,">0")
=sumif(a1:a10,"=2",b1:b10)/sumproduct((a1:a10=2)*(b1:b10<>0))
hth
Last edited by Cheeky Charlie; 11-13-2008 at 10:56 AM. Reason: Stop being a thickie CC
With A1:B11 containing this list:
and...Priority Value 2 5 3 6 1 16 1 8 2 10 2 12 0 15 3 3 2 30 0 9
D1: Priority
D2: 0
D3: 1
D4: 2
D5: 3
E1: Average
Then...this formula returns the average for Priority 0 items
Copy that formula down through E5E2: =SUMIF($A$2:$A$11,D2,$B$2:$B$11)/COUNTIF($A$2:$A$11,D2)
..OR...you could use a Pivot Table to automatically build the table.
Still using the above example...(Column heading must exist):
From the Excel Main Menu: <Data><Pivot Table>
Use: Excel……Click [Next]
Select your data…(A1:B11)…Click [Next]
Click the [Layout] button
ROW: Drag the Priority field here
COLUMN: (leave this area blank)
DATA: Drag the Value field here
If it doesn't list as Average of Value...dbl-click it and set it to Average
Click [OK]
Select where you want the Pivot Table…Click [Finish].
That will list each Priority and the Average Value.
Does that help?
To refresh the Pivot Table, just right click it and select Refresh Data
Ron, I missed this first time through - am I right in thinking you did too?I may have a 0 value in a cell next to a priority... i do not want this to be averaged
yeh... thats my problem guys... is it possible?
Yes....I surely missed the "skip zeros" critria, too.
Ok....Using the same example I posted
Try this formula
or...this shorter ARRAY FORMULA...BUT you need to remember to commitE2: =SUMPRODUCT(($A$2:$A$11=D2)*($B$2:$B$11>0)*$B$2:$B$11)/ SUMPRODUCT(($A$2:$A$11=D2)*($B$2:$B$11>0))
it with CTRL+SHIFT+ENTER (instead of just ENTER)
Copy the formula down through E5.E2: =AVERAGE(IF(($A$2:$A$11=D2)*($B$2:$B$11>0),$B$2:$B$11))
Does that help?
ok the first formula works wellthats great. What do you mean by commit? what does ctrl+shift+del do?
It's CTRL+SHIFT+ENTER
Regarding:
To make Excel treat the referenced cells as proper arrays,E2: =AVERAGE(IF(($A$2:$A$11=D2)*($B$2:$B$11>0),$B$2:$B$11))
after editing the cell you must:
• Hold down CTRL and SHIFT when you press ENTER
If you just commit the formula with ENTER..it will return incorrect values.
That's one of the pitfalls of ARRAY FORMULAS.
I hope that helps.
I think the sumproducts version I wrote first is neater...![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks