0
votes

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.

1
Do you have a dimension for ReferenceID?. Also, to confirm my understanding, you need to find the median for two days for each ReferenceID independently ?BICube
Yes, I have ReferenceID dimension. And, Yes, I need to find median for two days for each ReferenceID.Oblomingo

1 Answers

0
votes

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])
)