简体   繁体   中英

How use MEDIAN function to other hierarchy in MDX query?

Warehouse structure:

FactSales : ..., DateKey, RefernceId, SalesAmount, .....

  • DateKey - Date dimension key, ReferenceId - Sale Id, SalesAmount - sales amount for each sale (not for day).

    For example in two day were 6 sales. So in warehouse fact table will be 6 rows.

DateKey ReferenceID SalesAmount

2015-04-09 - 001 - 9

2015-04-09 - 002 - 10

2015-04-09 - 003 - 11

2015-04-10 - 004 - 12

2015-04-10 - 005 - 13

2015-04-10 - 006 - 14

DimDate : DateKey, Year, Quarter, Month, Date, ......

I have SSAS multidimensional cube and I want to query data for chart. Chart X axis will be Date, Y axis will be SalesAmount.

Ok, I must to show 2 day median. It is not a problem if we have granulation by days:

MEMBER [Measures].[2d median] AS
(
MEDIAN(
[Date].[Date].CurrentMember.Lag(2) :
[Date].[Date].CurrentMember.Lag(1), 
[Measures].[SalesAmount])
)

In this case MDX take two aggregated values and count meadian. But how to granulate data by RefenceId (by each sale)?

In this case MDX must take each sales value (for 2015-04-09 - 2015-04-10 will be 6 values).

I have no idea how to connect Date dimension to ReferenceId dimension. Should I create new Hierarchy with additional attribute?

Like this: ReferenceId -> Date -> Month -> Quarter -> Year.

Can you cross join the dates to each ReferenceID?

MEMBER [Measures].[2d median] AS
(
MEDIAN(
  [ReferenceID].currentmember *
  {[Date].[Date].CurrentMember.Lag(2) : [Date].[Date].CurrentMember.Lag(1)} 
 ,[Measures].[SalesAmount])
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM