Friday, March 23, 2012

Median calculation

I want to calculate the MEDIAN time interval between the two date field. In an OLAP cube one of the dimension consists of the two date fields as well as Interval(days) field (calculated at the data source view). How to create a Measure in the OLAP cube to calculate the MEDIAN Interval?

MEDIAN( <<Set>>[, <<Numeric Expression>>])

Since I'm not sure of the details your dimension, here's an Adventure Works sample query, for the Median duration in days of a Promotion:

>>

With Member [Measures].[MedPromoDays] as

Median(existing [Promotion].[Promotion].[Promotion],

DateDiff("d", [Promotion].[Promotion].Properties("Start Date", TYPED),

[Promotion].[Promotion].Properties("End Date", TYPED)))

select {[Measures].[MedPromoDays]} on 0,

[Promotion].[Promotion Type].Members on 1

from [Adventure Works]

MedPromoDays
All Promotions 83.5
Discontinued Product 53
Excess Inventory 61
New Product 91
No Discount 1309
Seasonal Discount 30
Volume Discount 1095

>>

|||

And to slightly change Deepak's query to be more efficient:

With Member [Measures].[MedPromoDays] as

Median(existing [Promotion].[Promotion].[Promotion],

DateDiff("d", [Promotion].[Start Date].MemberValue,

[Promotion].[End Date].MemberValue))

select {[Measures].[MedPromoDays]} on 0,

[Promotion].[Promotion Type].Members on 1

from [Adventure Works]

No comments:

Post a Comment