2016-07-19 17 views
0

SSASで計算メンバーの作成に問題があります。 ファクトテーブル:MDX(SSAS)のSQL subselect、group by、sum相当

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 

寸法: 日付、店舗、製品

私はそのような何かを取得したい: 私はいくつかの製品でフィルタする場合、私はこの店と日付ですべての売上を取得したいです私はStore1によって、すべての売上高を取得し、このSQLコードを実行

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

:私は製品1でフィルタしたい例えば濾過した生成物+他の製品別売上高を、含まれています。

計算されたメンバーを作成するには、MDXでどのように作成できますか?計算されるメンバの

出力は次でなければなりません:あなたの条件については

Product Total_Sales_By_Store 
------------------------------ 
Product1 50+100=150 
Product2 50+100+70+85=305 
Product3 70+85=155 

答えて

0

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] 
0
SELECT 
    [Measures].[Sales_in_USD] ON 0, 
    {[Store].[Store Name].MEMBERS, 
    [Product].[Product].MEMBERS} ON 1 
FROM [Cube Name]; 

対策があなた

のための仕事を行いますので、あなたは本当に、算出メンバーを必要としません特定の商品名商品1の場合は、

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

私は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];