Solved

Calculating "Median"(or any other aggregate function)  in OLAP cube****Urgent***$$$***

Posted on 2003-12-04
4
1,088 Views
Last Modified: 2012-09-07
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_id      time_id      customer_id      promotion_id      store_id      store_sales      store_cost      unit_sales
487            695      139            0            24            $7.80            $2.89            3
970            695      139            0            24            $12.44            $5.22            4
1080            695      139            0            24            $8.76            $4.20            4

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
0
Comment
Question by:ksurya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 9880185
if the median stuff isn't working in sql, write a vb com dll to return the correct value, then call the dll from sql server 7 or 2000. i've done stuff like this many times.

for the 500 points, i'll write it for you, both the sql side and the vb dll side.

the only sql part i'll write is calling the dll, passing in all values, and getting back the median. you do the rest.

if you're interested, "Accept" this answer and see my profile to get my email.
0
 
LVL 8

Accepted Solution

by:
Dishan Fernando earned 500 total points
ID: 9880260
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question