PC Review


Reply
Thread Tools Rate Thread

Averging data when criteria is met

 
 
cherman
Guest
Posts: n/a
 
      23rd Nov 2009
I have data that looks like this:

WW_Yr OpenDays Sminor Smedium Scritical Sundefined

WW01 14 1 0 0 0
WW01 1 0 1 0 0
WW02 15 1 0 0 0
WW02 129 0 0 1 0
WW03 17 0 0 0 0
WW04 13 1 0 0 0

etc.

This data starts in cell A1 and goes across to column M and the number of
rows can be different.

I can have 1 or more records with the same WW_Yr value. The other 5 columns
will have either the number "1" or "0". There will only be a "1" in one of
the fields and the rest will be "0".

I want to create a dynamic table based on this data, with the data starting
in cell O3, 4 columns wide and 26 rows.

I will add to the the 1st column to the sheet from code, which will have the
26 distinct WW_Yr values from my source data above.

The next column needs to be an average of OpenDays for each of the 26 WWW_Yr
value where Sminor = 1, or it needs to be a 0 if no records are found to meet
this criteria. It will work the same for Smedium, Scritical & Sundefined.

Any help on how I can do this averging with these conditions and build out
my table would be much appreciated.

Thanks,
Clint
 
Reply With Quote
 
 
 
 
Bernard Liengme
Guest
Posts: n/a
 
      23rd Nov 2009
Clint:
You have asked this in the programming newsgroup but it can all be done with
formulas
With the data you show starting in A1:
With O3 having the value WW01, O4 having WW02, etc
In P3 enter
=SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1),$B$1:$B$200)/SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1))
Carefully note the use of absolute and semi-absolute references. This allows
us to copy the formula across to column S and down to row 28

However, we get DIV0! errors in many cases, so we need to adapt this to
=IF(SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1)),SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1),$B$1:$B$200)/SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1)),0)

Note that the test SUMPRODUCT(--($A$1:$A$200=$O3),--(C$1:C$200=1)) will
compute to 0 or 1 which Excel will interpret as =IF(this_value<>0, do this,
do_that)

I have used A1:A200 but you can use any range. It does not matter if there
are empty rows. Except in Excel 2007 you cannot use full column references
(e.g B:B)

If you are using Excel 2007, we can use a more simple formula in P3:
=IFERROR(AVERAGEIFS(B:B,A:A,$O3,C:C,1),0)
This can be copied down the column, but when you copy across to Q3 you must
change C:C to D, and so on.

best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"cherman" <(E-Mail Removed)> wrote in message
news:6FDFE2EB-6C86-41E8-B430-(E-Mail Removed)...
>I have data that looks like this:
>
> WW_Yr OpenDays Sminor Smedium Scritical Sundefined
>
> WW01 14 1 0 0 0
> WW01 1 0 1 0 0
> WW02 15 1 0 0 0
> WW02 129 0 0 1 0
> WW03 17 0 0 0 0
> WW04 13 1 0 0 0
>
> etc.
>
> This data starts in cell A1 and goes across to column M and the number of
> rows can be different.
>
> I can have 1 or more records with the same WW_Yr value. The other 5
> columns
> will have either the number "1" or "0". There will only be a "1" in one of
> the fields and the rest will be "0".
>
> I want to create a dynamic table based on this data, with the data
> starting
> in cell O3, 4 columns wide and 26 rows.
>
> I will add to the the 1st column to the sheet from code, which will have
> the
> 26 distinct WW_Yr values from my source data above.
>
> The next column needs to be an average of OpenDays for each of the 26
> WWW_Yr
> value where Sminor = 1, or it needs to be a 0 if no records are found to
> meet
> this criteria. It will work the same for Smedium, Scritical & Sundefined.
>
> Any help on how I can do this averging with these conditions and build out
> my table would be much appreciated.
>
> Thanks,
> Clint


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query with criteria for long data type but criteria is double =?Utf-8?B?THluZGE=?= Microsoft Access Queries 1 30th Jan 2007 01:24 AM
Averging non-zero cells only Alienator Microsoft Excel Worksheet Functions 4 31st Jan 2006 07:14 PM
averging prices real problem amrezzat Microsoft Excel Programming 3 17th Nov 2005 06:31 PM
averging prices real problem amrezzat Microsoft Excel Worksheet Functions 6 17th Nov 2005 05:45 PM
data type mismatch in criteria expression when no criteria specified JR Microsoft Access Queries 1 27th Jul 2004 03:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:24 AM.