度量的不同度量聚合取决于包含的维度

时间:2017-09-13 18:11:05

标签: ssas mdx aggregation

我在测量聚合方面遇到了麻烦。 真实世界的情况是,客户想要分析购买数量与该周进入商店的顾客数量的比率。  我们知道每周输入的客户数量以及购买类型(昂贵,中等,便宜)的购买量。  由于存在不同的采购类型,因此会为该位置和该周创建多个行。因此,复制了相同的度量(NumberOfWalkInCustomers)。

These are the records. NumberOfWalkInCustomers are the totals per the Location and the WeekStartDate only. The duplicated rows are the result of the purchase Types. Without any dimensions in place, the sum looks like 850 but I would like to see the total as 650 because that's the total of Customers entered to those two locations in those two weeks.

我希望看到的是,当我在位置和日期维度内聚合时,该度量将得到总结。当其他维度到位时,如何避免总和聚合?

如果报告中包含日期,位置和购买类型维度,则看起来没问题  但是当我删除购买类型维度时,我希望Location1显示为100,因为购买类型不会影响输入到某个位置的客户数量。但是,当我删除Date Dimension时,我想看到Location1的250(第1周为100,第2周为150)。该网站允许我只添加两个链接。遗憾。

1 个答案:

答案 0 :(得分:0)

有两种方式:慢速和快速。

1(纯MDX):

With 
[Measures].[SumWeekStartDateSumLocationMaxPurchaseType] as
Sum(
      existing [Date].[Week Start Date].[Week Start Date].Members,
      [Measures].[2]
)


[Measures].[SumLocationMaxPurchaseType] as
Sum(
      existing [Store Location].[Location].[Location].Members,
      [Measures].[MaxPurchaseType]
)

[Measures].[MaxPurchaseType] as
Max(
      existing [Purchase Type].[Purchase Type].[Purchase Type].Members,
      [Measures].[Number Of Walk In Customers]
) 

select 
[Measures].[SumWeekStartDateSumLocationMaxPurchaseType] on 0
from [YourCube]

但是,对于大尺寸,您可能会觉得它很慢。

2(有点MDX + DWH):使用以下结构向您的多维数据集添加新度量:

select 
      WeekStartDate,
      Location,
      MaxWalkIn = max(WalkIn)
from FactTableWalkIn
group by WeekStartDate, Location

使用总和聚合+计算度量添加MaxWalkIn度量:

IIF(
      [Purchase Type].[Purchase Type].CurrentMember is [Purchase Type].[Purchase Type].DefaultMember,
      [Measures].[MaxWalkIn],
      [Measures].[Number Of Walk In Customers]
)