Solved

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

Posted on 2003-12-04
4
1,040 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

743 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

12 Experts available now in Live!

Get 1:1 Help Now