Average Per

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
If you Have a list of account numbers and amounts, is there a way in one forumla to get the average per account?
 
Create a PivotTable. Put the account # as the row field and the amounts as the data field. Then, change the statistic that Excel picks (probably sum) to Average.
If you Have a list of account numbers and amounts, is there a way in one forumla to get the average per account?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Special chars

Hi Aladin

Couldn't you just use

=SUM(B2:B10)/SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&""))

Of course. But the reason I invoke the formula with FREQUENCY is that it's a better approach to count the distinct items than the one with COUNTIF that fails with items which contais some special chars.

Thats a good point against countif in some circumstances (I never had the idea that someone uses specialchars)

These are ? and * and ~

Are there more by your experience?

So if these could occur you have to replace in the searchitem first ~ with ~~ and then the others with ~* and ~?


TX for this eyeopener!
 
Upvote 0
Re: Special chars

Hi Aladin

Couldn't you just use

=SUM(B2:B10)/SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&""))

Of course. But the reason I invoke the formula with FREQUENCY is that it's a better approach to count the distinct items than the one with COUNTIF that fails with items which contais some special chars.

Thats a good point against countif in some circumstances (I never had the idea that someone uses specialchars)

These are ? and * and ~

Are there more by your experience?

So if these could occur you have to replace in the searchitem first ~ with ~~ and then the others with ~* and ~?


TX for this eyeopener!

Entries like

<

< Tlex >
 
Upvote 0
Hi Aladin,
tx for this additional information.

Of course these must be problemst to.

Also my stomach turns around on the possibilty, that there are captions outside, which use one of these chars.

Perhaps with barcodes. :devilish:
But to get sensibilisized is important.

Thanks again
 
Upvote 0
Hi Aladin,
I'm so in this thing now, that I looked deeper in your formula.
And I found:
Excel Workbook
ABCD
1
2Haus50
3Hausen100
4Hausen100
5Haus*70160
6
7
8Haus50
9Hausen100
10Hausen100
11Hausa70106.6666667
Sheet


So there seems to be a problem too or am I wrong


Added:

And a string ending with ~ will give a problem too.
Due to the formula Match.
 
Upvote 0
Just in case someone responds to my post...I am no longer watching this topic since it seems to have become a series of posts on something not directly related to the original topic.
 
Upvote 0
Hi

Thats a good point against countif in some circumstances (I never had the idea that someone uses specialchars)

These are ? and * and ~

Are there more by your experience?

Besides the wildcards ("*", "?") and the escape character "~" I had problems with the comparison operators. If the first character is a comparison operator, countif interprets the value as a pattern.

I believe that using a direct comparison avoids all these problems:

=SUM(B2:B5)/SUM((A2:A5<>"")/MMULT(--(A2:A5=TRANSPOSE(A2:A5)),ROW(A2:A5)^0))

Remark: Another advange of this formula is that you can also use it if the record is defined by the combination of several columns, for example (Territory, Account). In this case you just have to add another term to the equation.

The problem here is to calculate the number of unique values. To illustrate the differences, I post several cases and the results of the number of unique values for the 3 formulas: the countif formula, the frequency formula and the comparison formula.

=SUMPRODUCT((A2:A5<>"")/COUNTIF(A2:A5,A2:A5&""))
=SUM(IF(FREQUENCY(IF(A2:A5<>"",MATCH("~"&A2:A5,A2:A5&"",0)),ROW(A2:A5)-ROW(A2)+1),1))
=SUM((A2:A5<>"")/MMULT(--(A2:A5=TRANSPOSE(A2:A5)),ROW(A2:A5)^0))
The last 2 are CSE.

Please test it.

Kind regards
PGC

P. S. Although I wrote all this about the problems of using Countif to count the unique values, the truth is that the countif formula is the one that I use the most.
In fact, the special characters are not usually a problem, like in this Oorang problem with account numbers and amounts.
Book1
ABCDEF
1AverageCountifFrequencyComparison
2Haus50
3Hausen100
4Hausen100
5Haus*70106.66672.2523
6
7Haus50
8Hausen100
9Hausen100
10Hausa70106.6667333
11
12Haus50
13Hausen100
14Hausen100
15Haus~70106.6667323
16
17Haus50
18Hausen100
19Hausen100
20Hau?70106.66672.523
21
22
23Hausen100
24Hausen100
25Haus~701352#N/A2
26
27Haus50
28Hausen100
29Hausen100
30<=Haus70106.66672.533
Sheet4
 
Upvote 0

Forum statistics

Threads
1,216,058
Messages
6,128,538
Members
449,456
Latest member
SammMcCandless

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