2016-04-03 117 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