Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 788
Default sumif and average with limits... pls help....

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

50 20 10 30 60 40 80

I need to average the data that is under "CD" but ONLY the first 2..(50 and
10).
How can I set the limit?? (btw, I will be using Hlookup to get the "CD"
criteria)
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 788
Default sumif and average with limits... pls help....

please take note of the changes.

"Chris" wrote:

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

Sales 50 20 10 30 60 40 80


Expense 30 10 60 20 70 90
50

I need to average the data that is under "CD" and only those in the 2nd row(expense) but ONLY the first 2..(30 and 60).
How can I set the limit??

  #3   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default sumif and average with limits... pls help....

If your table is in A1:H3, you could enter this in C10
=MIN(2,COUNTIF(B1:H1,"CD"))

and this, array entered using Ctrl+Shift+Enter, in D10
=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)/C10

although there could be a better way



"Chris" wrote:

please take note of the changes.

"Chris" wrote:

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

Sales 50 20 10 30 60 40 80


Expense 30 10 60 20 70 90
50

I need to average the data that is under "CD" and only those in the 2nd row(expense) but ONLY the first 2..(30 and 60).
How can I set the limit??

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 788
Default sumif and average with limits... pls help....

tnx JMB,

can u explain to me how the formula works so that next time I can do it on
my own. Tnx a lot.

"JMB" wrote:

If your table is in A1:H3, you could enter this in C10
=MIN(2,COUNTIF(B1:H1,"CD"))

and this, array entered using Ctrl+Shift+Enter, in D10
=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)/C10

although there could be a better way



"Chris" wrote:

please take note of the changes.

"Chris" wrote:

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

Sales 50 20 10 30 60 40 80


Expense 30 10 60 20 70 90
50

I need to average the data that is under "CD" and only those in the 2nd row(expense) but ONLY the first 2..(30 and 60).
How can I set the limit??

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 788
Default sumif and average with limits... pls help....

Btw, will this formula work if I my data is less than 2??? Will it still
average?? Tnx.

"Chris" wrote:

tnx JMB,

can u explain to me how the formula works so that next time I can do it on
my own. Tnx a lot.

"JMB" wrote:

If your table is in A1:H3, you could enter this in C10
=MIN(2,COUNTIF(B1:H1,"CD"))

and this, array entered using Ctrl+Shift+Enter, in D10
=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)/C10

although there could be a better way



"Chris" wrote:

please take note of the changes.

"Chris" wrote:

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

Sales 50 20 10 30 60 40 80

Expense 30 10 60 20 70 90
50

I need to average the data that is under "CD" and only those in the 2nd row(expense) but ONLY the first 2..(30 and 60).
How can I set the limit??



  #6   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default sumif and average with limits... pls help....

In order to see what is happening (and given the assumption that your sample
table is in A1:H3 with labels in row 1 and column A), select a block of cells
that is 7 rows by 1 column. Then enter this (which I picked up from one of
Harlan Groves posts) in the formula bar and hit Ctrl+Shift+Enter

=MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3))))

This returns a running subtotal of your expense data.
30
40
100
120
190
280
330

By multiplying B3:H3 by (B1:H1="CD"), I get a running subtotal that only
includes expense items for "CD". This is due to the fact that excel stores
TRUE as 1 and FALSE as 0. So multiplying B3:H3 by an array of 1's (for CD)
and 0's (other values) causes the items that don't fit your criteria to drop
out:

=MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))

returns
30
30
90
90
160
160
160

The IF function eliminates duplicated values by testing B1:H1 for "CD" and
returning the corresponding value from the array returned by MMULT, otherwise
it returns FALSE

=IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD")))))

returns
30
FALSE
90
FALSE
160
FALSE
FALSE

Then I used the Small function to return the second smallest number in the
above array (small ignores FALSE)

=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)

returns 90

Instead of hardcoding "2" in the Small function, I reference cell C10 which
contains
=MIN(2,COUNTIF(B1:H1,"CD"))

If there are fewer than 2 occurences of CD in B1:H1, Min returns the actual
count. Then divide the subtotal figure returned by Small by the number in
C10 to get the average

=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)/C10

which gives you 90/2 = 45.

You could move your criteria to other cells to make it more flexible. You
could use A10 and B10 as input cells so that you can easily modify your
criteria without having to edit the formula every time:

A10 = CD
B10 = 2
C10 = MIN(B10,COUNTIF(B1:H1,A10))
D10 =
IF(C100,SMALL(IF(TRANSPOSE(B1:H1=A10),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1=A10))))),C10)/C10,0)

adding a check to ensure C10 is greater than 0, otherwise you'll get an error.


"Chris" wrote:

Btw, will this formula work if I my data is less than 2??? Will it still
average?? Tnx.

"Chris" wrote:

tnx JMB,

can u explain to me how the formula works so that next time I can do it on
my own. Tnx a lot.

"JMB" wrote:

If your table is in A1:H3, you could enter this in C10
=MIN(2,COUNTIF(B1:H1,"CD"))

and this, array entered using Ctrl+Shift+Enter, in D10
=SMALL(IF(TRANSPOSE(B1:H1="CD"),MMULT(--(TRANSPOSE(COLUMN(B1:H1))=COLUMN(B1:H1)),--(TRANSPOSE((B3:H3)*(B1:H1="CD"))))),C10)/C10

although there could be a better way



"Chris" wrote:

please take note of the changes.

"Chris" wrote:

I need to average a group of data with a criteria but only up to a certain
number.

Sample:

CD AG CD FG CD FG AG

Sales 50 20 10 30 60 40 80

Expense 30 10 60 20 70 90
50

I need to average the data that is under "CD" and only those in the 2nd row(expense) but ONLY the first 2..(30 and 60).
How can I set the limit??

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there formula similar to SUMIF that will work for average johnu Excel Discussion (Misc queries) 2 April 24th 08 06:18 PM
SUMIF for an AVERAGE TiaB Excel Worksheet Functions 2 February 18th 07 05:09 AM
Average/Sumif based on several columns mslabbe Excel Worksheet Functions 3 February 4th 07 09:40 PM
Average/Sumif based on several columns mslabbe Excel Worksheet Functions 0 February 4th 07 05:49 PM
Weighted average using SUMIF and/or SUMPRODUCT MB51 Excel Discussion (Misc queries) 3 February 1st 07 07:39 PM


All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"