简体   繁体   English

如何在MDX查询中将MEDIAN函数用于其他层次结构?

[英]How use MEDIAN function to other hierarchy in MDX query?

Warehouse structure: 仓库结构:

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

  • DateKey - Date dimension key, ReferenceId - Sale Id, SalesAmount - sales amount for each sale (not for day). DateKey-日期维度键,ReferenceId-销售ID,SalesAmount-每次销售的销售金额(非当天)。

    For example in two day were 6 sales. 例如在两天内进行了6次销售。 So in warehouse fact table will be 6 rows. 因此在仓库事实表中将有6行。

DateKey ReferenceID SalesAmount DateKey参考ID SalesAmount

2015-04-09 - 001 - 9 2015-04-09-001-9

2015-04-09 - 002 - 10 2015-04-09-002-10

2015-04-09 - 003 - 11 2015-04-09-003-11

2015-04-10 - 004 - 12 2015-04-10-004-12

2015-04-10 - 005 - 13 2015-04-10-005-13

2015-04-10 - 006 - 14 2015-04-10-006-14

DimDate : DateKey, Year, Quarter, Month, Date, ...... DimDate :DateKey,年,季度,月,日期,......

I have SSAS multidimensional cube and I want to query data for chart. 我有SSAS多维立方体,我想查询数据以获取图表。 Chart X axis will be Date, Y axis will be SalesAmount. 图表X轴为日期,Y轴为SalesAmount。

Ok, I must to show 2 day median. 好的,我必须显示2天的中位数。 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. 在这种情况下,MDX取两个聚合值并计数meadian。 But how to granulate data by RefenceId (by each sale)? 但是如何通过RefenceId(按每次销售)细化数据?

In this case MDX must take each sales value (for 2015-04-09 - 2015-04-10 will be 6 values). 在这种情况下,MDX必须采用每个销售值(对于2015-04-09-2015-04-10将为6个值)。

I have no idea how to connect Date dimension to ReferenceId dimension. 我不知道如何将日期维度连接到ReferenceId维度。 Should I create new Hierarchy with additional attribute? 我应该使用其他属性创建新的层次结构吗?

Like this: ReferenceId -> Date -> Month -> Quarter -> Year. 像这样:ReferenceId->日期->月->季度->年。

Can you cross join the dates to each ReferenceID? 您可以将日期与每个ReferenceID交叉吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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