Solved

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

Posted on 2003-12-04
4
1,047 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
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:
dishanf earned 500 total points
ID: 9880260
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now