Coefficient of Dispersion: Create a UDF to average a range of cells

PSJupiter2

New Member
Joined
Mar 18, 2015
Messages
7
I wish to create a UDF that calculates a formula used in Mass Appraisal of Real Estate

I use MS Excel 2007, and Windows 7

This is a sample what my Data looks like:

[TABLE="width: 250"]
<tbody>[TR]
[TD]AssessedValue[/TD]
[TD]SalePrice[/TD]
[TD]Ratio = AV/SP[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]88[/TD]
[TD]1.02
[/TD]
[/TR]
[TR]
[TD]90
[/TD]
[TD]93[/TD]
[TD]0.97[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]87[/TD]
[TD]1.03[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]94[/TD]
[TD]0.96[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]85[/TD]
[TD]1.06[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]96[/TD]
[TD]0.94[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]95[/TD]
[TD]0.95[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]98[/TD]
[TD]0.92[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]100[/TD]
[TD]0.90[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]90[/TD]
[TD]1.00[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]90[/TD]
[TD]1.00[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]98[/TD]
[TD]0.92[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]97[/TD]
[TD]0.93[/TD]
[/TR]
[TR]
[TD]90[/TD]
[TD]90[/TD]
[TD]1.00[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


My data ranges will be different every time I use the UDF ("n" is based on the number of data points available)


To my knowledge, there is no built-in formula for the following:

Control - Shift - Enter:
{=((AVERAGE(ABS(C2:C15-(MEDIAN(C2:C15)))))/(MEDIAN(C2:C15)))*100}


I thought a UDF would be the way to go. I am trying to accomplish the following:


Function COD(Ratio, Median)

COD= {((AVERAGE(ABS("Range of available data" - "Median of Available Data"))))/(MEDIAN("Median of Available Data"))*100}

End Function


Any help on this would be greatly appreciated! Thank You!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Isn't the coefficient of dispersion the variance divided by the mean?

=VARP(data)/Average(data)
 
Upvote 0
Isn't the coefficient of dispersion the variance divided by the mean?

=VARP(data)/Average(data)



Hi shg:

Thanks for the quick reply. Unfortunately, VARP uses the average of the data set. In the Mass Appraisal context, Coefficient of Dispersion uses the Median to test for average deviation.

Average Deviation = [ ∑ |Ratio – Median| ] / n

COD = [ (average deviation) / Median] * 100
While your formula would work for the average, it will not work for my purposes.

Thanks again for the suggestion!
 
Upvote 0
Cheap & cheerful:

Code:
Function COD(r As Range) As Double
  Dim sAdr As String
  Dim sFrm As String
  
  sAdr = r.Address
  sFrm = "average(abs(" & sAdr & " - median(" & sAdr & ")))/median(" & sAdr & ")"
  COD = r.Worksheet.Evaluate(sFrm)
End Function

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][/tr]
[tr][td]
1​
[/td][td]
61​
[/td][td][/td][td]
0.482609​
[/td][td]C1: {=AVERAGE(ABS(A1:A10 - MEDIAN(A1:A10)))/MEDIAN(A1:A10)}[/td][/tr]

[tr][td]
2​
[/td][td]
27​
[/td][td][/td][td]
0.482609​
[/td][td]C2: =COD(A1:A10)[/td][/tr]

[tr][td]
3​
[/td][td]
65​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
4​
[/td][td]
74​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
5​
[/td][td]
90​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
6​
[/td][td]
53​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
7​
[/td][td]
14​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
8​
[/td][td]
36​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
9​
[/td][td]
5​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td]
10​
[/td][td]
39​
[/td][td][/td][td][/td][td][/td][/tr]
[/table]
 
Upvote 0
Thank You shg!!

This worked just as intended. Now I just need to learn the components of this formula!





Cheap & cheerful:

Code:
Function COD(r As Range) As Double
  Dim sAdr As String
  Dim sFrm As String
  
  sAdr = r.Address
  sFrm = "average(abs(" & sAdr & " - median(" & sAdr & ")))/median(" & sAdr & ")"
  COD = r.Worksheet.Evaluate(sFrm)
End Function

[TABLE="class: grid"]
<tbody>[TR]
[TD]Row\Col[/TD]
[TD]
A​
[/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD]
61​
[/TD]
[TD][/TD]
[TD]
0.482609​
[/TD]
[TD]C1: {=AVERAGE(ABS(A1:A10 - MEDIAN(A1:A10)))/MEDIAN(A1:A10)}[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD]
27​
[/TD]
[TD][/TD]
[TD]
0.482609​
[/TD]
[TD]C2: =COD(A1:A10)[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]
65​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]
74​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]
90​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
6​
[/TD]
[TD]
53​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
7​
[/TD]
[TD]
14​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
8​
[/TD]
[TD]
36​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
9​
[/TD]
[TD]
5​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10​
[/TD]
[TD]
39​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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