Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

773 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