Hello everyone,
I am very new to vba and need a UDF to calculate 'weighted median'. You know 'weighted average', but 'weighted median' is different which is 'the 50% weighted percentile'.
Suppose there are two columns: column A for weight (%), and column B for age. To manually get the 'weighted median', I need to do two steps:
1) sort data from the highest to the lowest value based on column B.
2) from the first cell in column A, keep adding up the weights until it reached a total of 50%. The cell in column B which makes up the total weight of 50% is the value 'weighted median'.
Can a UDF to accomplish the above two steps to get the value I want? The UDF will allow me to get the 'weighted median' by specifying: =WTMEDIAN(A1:A20,B1:B20).
An example is attached here.
image001.png
Bookmarks