Calculating Median:*** Help** Urgent**$$$$

  • Hello all,

    Myself and few other guys are working on this problem from past few days but no break-through yet.

    We are trying to figure out calculating "Median"

    Here is the business problem:

    In "Foodmart" database (standardly delivered with MS SQL server Analysis Services)

    1. I picked a customer: customer_id = 139 (Cusromer Table). Belongs to Coronado (city), CA (State)

    2. for this customer we have 3 sale records (in sales_fact_1997) table

    product_idtime_idcustomer_idpromotion_idstore_idstore_salesstore_costunit_sales

    487695139024$7.80$2.893

    970695139024$12.44$5.224

    1080695139024$8.76$4.204

    Lets calculate (Only for customer 139)

    Total No of records: 3

    Total Store Sales: $7.80 + $12.44 + $8.76 = $29

    Average Store Sales: $29/3 = $9.67

    Median Store Sales: $7.80, $8.76, $12.44 = $8.76

    Now I was trying to get the same result in Analysis Services

    I created a formula under "Sales" cube

    MedianCustomerSales = Median({[Customers]},[Measures].[Store Sales]) Hoping it would work

    However when I do a browse data for Sales cube (Also creted a pivot table in excel and tried)

    Surprisingly MedianStoreSales value os also displayed as $29.

    "Why?"

    If you ever worked with Median or StdDev type of functions (caculated based on population) please help.

    Question 2: I do not want to limit calculating Median by Customer, I want to give option to see "median store sales" based on the dimention user select while browsing the

    data like Department or Product Or Store. How?

    Please do call me 443-983-3133 or mail me at ksurya@inventumtech.com

    Regards

    Surya

  • Hey Surya,

    Regarding your first question, Median(<set>[,<numeric>]) definitely works. I must have killed off some of my transactions, because I don't have the CA customer that you are using, but using USA.OR.Corvallis (ie MEdian([Customers].[USA].[OR].[Corvallis].Children, [MEasures].Store Sales]) I definitely get the median value.

    Median won't (or shouldn't anyway) return the median of the SOURCE records. These get aggregated across the dimensions, using the meausres you have put into your cube. Keep in mind you are looking at summary data, the transaction level is "lost" until you drill back to the detail (often called drill through). It will return the median of records as they exist in the cube (ie the aggregated records).

    Your example of the three transactions sort of proves this, if you were looking only at the customer dimension then there is effectively only 1 record (the sum, or $~29). If you were to put the product on say columns, then you should see three *transactions* which should then give you the *correct* median.

    On your second question, I have wanted to do this since starting with AS (as Cognos does this easily) but haven't yet found a way of making a calculated member that dynamically refers to either the current row or column members - maybe this is not possible as the client is unknown (as far as MSAS is concerned)?

    HTH,

    Steve.

    Steve.

  • Surya,

    I'm now thinking maybe your specification of the set was incorrect, as the three transactions should all have been present int eh cube (based on using the standard foodmart cube).

    Maybe if you specified the Products dimension, but filtered to the appropriate date and also customer (139), then you may get what you were looking for.

    Basically you need to specify a set of records to obtain the median from, where before I think it would have resolved to a single record (totalling $29).

    HTH,

    Steve.

    Steve.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply