Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
AMB AMB is offline
external usenet poster
 
Posts: 4
Default Calculating the Median Price Sold

Hello,

I am trying to find a reasonable way of calculating a median. I have a data
set that is about 20,000 lines long and it contains Quantity Sold and Unit
Price. I need to calculate out the Median Price Sold. Is there a way to
count the Unit Price mulitple times based on the Quantity Sold so that I end
up with an accurate Median?

The dataset appears as follows:

Quantity Sold Unit Price
1 330.00
5 300.00
3 330.00
5 360.00
4 360.00
4 330.00
3 369.00
1 374.00

Regards,

Adam


--
Adam Brody
National Business Analyst
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Calculating the Median Price Sold

You need a UDF. I copied this a long time ago and can't remember the name of
the original author so apologies to whoever it was.

Alt +F11 to open VB editor, Double click 'This Workbook' and paste this in
on the right.

Function WeightedMedian(ValueRange As Range, WeightRange As Range)
Dim MedianArray()
On Error GoTo WrongRanges
ArrayLength = Application.Sum(WeightRange)
ReDim MedianArray(1 To ArrayLength)
Counter = 0
ArrayCounter = 0
For Each ValueRangeCell In ValueRange
LoopCounter = LoopCounter + 1
FirstArrayPos = ArrayCounter + 1
ArrayCounter = ArrayCounter + Application.Index(WeightRange,
LoopCounter)
For n = FirstArrayPos To ArrayCounter
MedianArray(n) = ValueRangeCell.Value
Next
Next
WeightedMedian = Application.Median(MedianArray)
Exit Function
WrongRanges:
WeightedMedian = CVErr(2016)
End Function

call with
=WeightedMedian(B1:B8,A1:A8)
It returns 345

Mike


WrongRanges:
WeightedMedian = CVErr(2016)
End Function


"AMB" wrote:

Hello,

I am trying to find a reasonable way of calculating a median. I have a data
set that is about 20,000 lines long and it contains Quantity Sold and Unit
Price. I need to calculate out the Median Price Sold. Is there a way to
count the Unit Price mulitple times based on the Quantity Sold so that I end
up with an accurate Median?

The dataset appears as follows:

Quantity Sold Unit Price
1 330.00
5 300.00
3 330.00
5 360.00
4 360.00
4 330.00
3 369.00
1 374.00

Regards,

Adam


--
Adam Brody
National Business Analyst

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Calculating the Median Price Sold

Found it

With respect to the original author
David Hager

Mike

"Mike H" wrote:

You need a UDF. I copied this a long time ago and can't remember the name of
the original author so apologies to whoever it was.

Alt +F11 to open VB editor, Double click 'This Workbook' and paste this in
on the right.

Function WeightedMedian(ValueRange As Range, WeightRange As Range)
Dim MedianArray()
On Error GoTo WrongRanges
ArrayLength = Application.Sum(WeightRange)
ReDim MedianArray(1 To ArrayLength)
Counter = 0
ArrayCounter = 0
For Each ValueRangeCell In ValueRange
LoopCounter = LoopCounter + 1
FirstArrayPos = ArrayCounter + 1
ArrayCounter = ArrayCounter + Application.Index(WeightRange,
LoopCounter)
For n = FirstArrayPos To ArrayCounter
MedianArray(n) = ValueRangeCell.Value
Next
Next
WeightedMedian = Application.Median(MedianArray)
Exit Function
WrongRanges:
WeightedMedian = CVErr(2016)
End Function

call with
=WeightedMedian(B1:B8,A1:A8)
It returns 345

Mike


WrongRanges:
WeightedMedian = CVErr(2016)
End Function


"AMB" wrote:

Hello,

I am trying to find a reasonable way of calculating a median. I have a data
set that is about 20,000 lines long and it contains Quantity Sold and Unit
Price. I need to calculate out the Median Price Sold. Is there a way to
count the Unit Price mulitple times based on the Quantity Sold so that I end
up with an accurate Median?

The dataset appears as follows:

Quantity Sold Unit Price
1 330.00
5 300.00
3 330.00
5 360.00
4 360.00
4 330.00
3 369.00
1 374.00

Regards,

Adam


--
Adam Brody
National Business Analyst

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
AMB AMB is offline
external usenet poster
 
Posts: 4
Default Calculating the Median Price Sold

Mike,

Thanks for your assistance. It worked perfectly.

Adam



"Mike H" wrote:

You need a UDF. I copied this a long time ago and can't remember the name of
the original author so apologies to whoever it was.

Alt +F11 to open VB editor, Double click 'This Workbook' and paste this in
on the right.

Function WeightedMedian(ValueRange As Range, WeightRange As Range)
Dim MedianArray()
On Error GoTo WrongRanges
ArrayLength = Application.Sum(WeightRange)
ReDim MedianArray(1 To ArrayLength)
Counter = 0
ArrayCounter = 0
For Each ValueRangeCell In ValueRange
LoopCounter = LoopCounter + 1
FirstArrayPos = ArrayCounter + 1
ArrayCounter = ArrayCounter + Application.Index(WeightRange,
LoopCounter)
For n = FirstArrayPos To ArrayCounter
MedianArray(n) = ValueRangeCell.Value
Next
Next
WeightedMedian = Application.Median(MedianArray)
Exit Function
WrongRanges:
WeightedMedian = CVErr(2016)
End Function

call with
=WeightedMedian(B1:B8,A1:A8)
It returns 345

Mike


WrongRanges:
WeightedMedian = CVErr(2016)
End Function


"AMB" wrote:

Hello,

I am trying to find a reasonable way of calculating a median. I have a data
set that is about 20,000 lines long and it contains Quantity Sold and Unit
Price. I need to calculate out the Median Price Sold. Is there a way to
count the Unit Price mulitple times based on the Quantity Sold so that I end
up with an accurate Median?

The dataset appears as follows:

Quantity Sold Unit Price
1 330.00
5 300.00
3 330.00
5 360.00
4 360.00
4 330.00
3 369.00
1 374.00

Regards,

Adam


--
Adam Brody
National Business Analyst

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
inventory Add, Cost, Sold, Sold price - formula Summer Excel Discussion (Misc queries) 3 July 20th 08 06:26 PM
Auto Filter - Calculating Median John Y Excel Worksheet Functions 1 January 4th 08 06:21 PM
calculating median and mode russelmiller Excel Worksheet Functions 5 November 27th 07 10:16 PM
Calculating Median Value in a large array willcozz Excel Discussion (Misc queries) 5 December 11th 06 10:21 PM
calculating a price John Excel Worksheet Functions 3 November 15th 06 06:11 PM


All times are GMT +1. The time now is 08:51 AM.

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"