2016-04-03 129 views
0

我想使用MDX查詢在SSAS中創建計算度量。該措施應在一年內和去年同期內返還平均金額。我已經發現了ParallelPeriod函數,但無法使用它。SSAS mdx查詢ParallelPeriod

我的查詢應該是這樣的

(
AGGREGATE(
    {[TF_Product].[LastDayOfMonth]} 
    *{[TF_Product].[Category].&[Deposits]}, 
    [Measures].[Montant] 
) 
+ 
AGGREGATE(
    { Get the date of the same period last year using parallelperiod} 
    *{[TF_Product].[Category].&[Deposits]}, 
    [Measures].[Montant] 
) 
)/2 

Screenshot

謝謝。

+0

The Daily average?那麼'(1jan-4Apr2015 + 1jan-4Apr2016)/ numdays'? – whytheq

+0

我想計算例如:(2016年1月的金額+ 2015年1月的金額)/ 2 – yasmine92

回答

0

做了這樣的工作嗎?

... 
MEMBER [Measures].[Avg of 2 Mths] AS 
    Avg(
    {[Date].[Month].CurrentMember.Lag(12),[Date].[Month].CurrentMember} 
    [Measures].[Sales Quantity] 
) 
... 

它工作在這種情況下:

WITH 
    MEMBER [Measures].[Avg of 2 Mths] AS 
    Avg 
    (
     { 
     [Date].[Calendar].CurrentMember.Lag(12) 
     ,[Date].[Calendar].CurrentMember 
     } 
,[Measures].[Internet Sales Amount] 
) 
SELECT 
    {[Measures].[Internet Sales Amount],[Measures].[Avg of 2 Mths]} ON 0 
,[Date].[Calendar].[Month] ON 1 
FROM [Adventure Works]; 

這是結果:

enter image description here

(755527.89 + 577314)/ 2 = 666420.95

+0

它不工作! – yasmine92

+0

@ yasmine92不是最有用的評論! – whytheq

+0

對不起! :(我會再試一次 – yasmine92

0

這工作?

with member [Measures].AvgAmnt as 
(
AGGREGATE(
    {[TF_Product].[Calendar].Currentmember} 
    *{[TF_Product].[Category].Currentmember}, 
    [Measures].[Montant] 
) 
+ 
AGGREGATE(
    {ParallelPeriod([TF_Product].[Calendar].[Month],1,[TF_Product].[Calendar].Currentmember)} 
    *{[TF_Product].[Category].Currentmember}, 
    [Measures].[Montant] 
) 
)/2 

select [TF_Product].[Calendar].[Date].members * [TF_Product].[Category].members on 1, 
[Measures].AvgAmnt on 0 
from [SomeCube] 

假設您在多維數據集中有一個Date層次結構(日曆)。

+0

不,我沒有時間層次結構在我的多維數據集中我一直在嘗試使用你的代碼但它不起作用沒有任何方法沒有層次結構嗎 – yasmine92

+0

'ParallelPeriod'的概念在沒有時間層次的情況下是不可用的你在立方體中有連續的日期嗎?還是有與交易有關的日期(以哪種情況下可能存在「差距」)? – SouravA

+0

日期不是連續的我有月份和年份的月份的最後一天 – yasmine92