SQL MDX(SSAS) 中的子选择、分组依据、求和等价物

SQL subselect, group by, sum equivalent in MDX(SSAS)

我在 SSAS 中创建计算成员时遇到问题。 事实 table:

  Date       Store       Product        Sales_in_USD
    --------------------------------------------------
    2016-07-01 Store1      Product1       50
    2016-07-01 Store1      Product2       100
    2016-07-01 Store2      Product3       70
    2016-07-01 Store2      Product2       85

维度: 日期、商店、产品

我想要这样的东西: 如果我按某些产品过滤,我想获得该商店的所有销售额和日期,包括按过滤产品+其他产品的销售额,例如我想按 Product1:

过滤
SQL code:
select sum(Sales_in_USD)
from [Fact table]
where Store in (select Store from [Fact table] where Product="Product1")

执行此 sql 代码,我获得了 Store1 的所有销售额。

当我想创建计算成员时,如何使用 MDX 创建它?

计算成员的输出必须是下一个:

Product   Total_Sales_By_Store
------------------------------
Product1  50+100=150
Product2  50+100+70+85=305
Product3  70+85=155
SELECT 
  [Measures].[Sales_in_USD] ON 0,
  {[Store].[Store Name].MEMBERS,
   [Product].[Product].MEMBERS} ON 1
 FROM [Cube Name];

根据您的要求,您确实不需要计算成员,因为度量会为您完成这项工作

对于特定产品名称 Product1,则

SELECT 
  [Measures].[Sales_in_USD] ON 0,
  {[Product].[Product].&[Product1],
   [Store].[Store Name].MEMBERS
  } ON 1
FROM [Cube Name];

1 - 确定所选产品的有效商店。

NonEmpty(
    [Store].[Store Name].MEMBERS,
    ([Product].[Product].Currentmember,[Measures].[Sales_in_USD])
)

2 - 拥有当前产品的商店后,您想要计算可能元组的值总和(交叉连接)。

with member Measures.[Total Sum of Stores] as
sum(
[Product].[Product].Currentmember *
NonEmpty
   (
    [Store].[Store Name].MEMBERS,
    ([Product].[Product].Currentmember,[Measures].[Sales_in_USD])
   )    
,
[Measures].[Sales_in_USD]
)

select Measures.[Total Sum of Stores] on 0
from [YourCube]
where [Product].[Product].[Product1]

我认为 Sourav 已经很好地掌握了它,但它还可以更通用吗?

WITH 
MEMBER [Measures].[Total Sum of Stores] AS
SUM(
  NONEMPTY(
    [Store].[Store Name].MEMBERS,
    (
      [Product].[Product].Currentmember
     ,[Measures].[Sales_in_USD]
    )
  )    
  ,[Measures].[Sales_in_USD]
)
SELECT
 [Measures].[Total Sum of Stores] on 0,
 [Product].[Product].[Product].MEMBERS ON 1
FROM [YourCube];