Average function that stops counting if another argument is met

Krabben

New Member
Joined
Aug 19, 2020
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello Mr. excel forum :)

I'm looking for a formula that can find the average that stops counting if another argument is met.

In the picture below, i've divided it into 5 different "layers".
In these layers, the average value of the numbers in the column A, should be given in column C, if the number in the column B matches eachother.

1604935413001.png


Hope you guys understand my question. Any ideas?


Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You can use the Averageif function for that
 
Upvote 0
You can use the Averageif function for that
Hey Fluff

My averageif function seems to include layers of the same column number, even if they are not in the same layer.

Any tips how to avoid that?
 
Upvote 0
Since you appear to have the same number repeating in column B but for different 'layers' you could do something like this:

Book1
ABC
1ValueBandAverage
2595.2
3395.2
4695.2
5495.2
6895.2
7152.7
8252.7
9552.7
10665.0
11465.0
12355.5
13855.5
14764.4
15664.4
16564.4
17364.4
18164.4
19064.4
20864.4
21164.4
22364.4
23564.4
24964.4
Sheet1
Cell Formulas
RangeFormula
C2:C24C2=IF(B2=B1,C1,AVERAGE(A2:INDEX(A2:A$25,MATCH(TRUE,B2:B$25<>B2,0)-1)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
I hadn't noticed that the values in B repeat, but should be treated separately.
Try Rory's formula.
 
Upvote 0
Since you appear to have the same number repeating in column B but for different 'layers' you could do something like this:

Book1
ABC
1ValueBandAverage
2595.2
3395.2
4695.2
5495.2
6895.2
7152.7
8252.7
9552.7
10665.0
11465.0
12355.5
13855.5
14764.4
15664.4
16564.4
17364.4
18164.4
19064.4
20864.4
21164.4
22364.4
23564.4
24964.4
Sheet1
Cell Formulas
RangeFormula
C2:C24C2=IF(B2=B1,C1,AVERAGE(A2:INDEX(A2:A$25,MATCH(TRUE,B2:B$25<>B2,0)-1)))
Press CTRL+SHIFT+ENTER to enter array formulas.
Thank you Rory, that did the trick :)
 
Upvote 0
Glad we could help. :)
 
Upvote 0
Glad we could help. :)
Hey Rory, sorry to bother you again. Thought you had solved my problem :/

So the code you provided works great, if, the "band" number changes. If it doesn't, it returns #I/T.

Im looking for the average in a predefined range (eg. A4-A50), and when i drag it down, sometimes the band matches all through the array.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,592
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top