2016-05-26 11 views
0

OLAPに基づくレポートの場合は、今年のデータと前年のパラレルのデータをexctractする必要があります。mdx期間からデータを選択

今日は2016年5月26日、 されている場合、私は日付のこれらの期間を必要とする:2016年1月1日 - 2016年5月26日と2015年1月1日 - 2015年5月26日

SELECT NON EMPTY 
    { [Measures].[Sell In Return] } ON COLUMNS, 

NON EMPTY { (

[Date].[Date].[Date].ALLMEMBERS * 
[Product].[Prod Name].[Prod Name].ALLMEMBERS * 
[Product].[Product].[Product].ALLMEMBERS * 
[Date].[Month Calendar].[Month Calendar].ALLMEMBERS 

) } 

DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME 
ON ROWS 

FROM 
[Table] 
+0

今後キューブの日付ディメンションに将来の日付があるのか​​、今日のキューブの最後の日付ですか? (私たちのキューブには将来の日がありませんので、テール([Date]。[Month Calendar]。[Date]) 'は今日です) – whytheq

+0

' [Date] [カレンダーの日] '? – whytheq

+0

はい、私は予測のための将来の日を持っています – Nastya

答えて

0

ここでキューブのTodayを見つけるスタートです。私は、カラムにスライサーと今日のための措置を移動した:

WITH 
    MEMBER [Measures].[Key for Today] AS 
    Format 
    (
     Now() 
    ,'yyyyMMdd' 
    ) 
    MEMBER [Measures].[Today string] AS 
     '[Date].[Month Calendar].[Calendar Day].&[' + [Measures].[Key for Today] 
    + ']' 
    SET [Today] AS 
    StrToMember 
    (
     [Measures].[Today string] 
    ,constrained 
    ) 
    SET [TodayLstYr] AS 
    ParallelPeriod 
    (
     [Date].[Date - Calendar Month].[Calendar Year] 
    ,1 
    ,[Today] 
    ) 
    SET [ThisYear] AS 
    { 
     Ancestor 
     (
      [Today] 
     ,[Date].[Month Calendar].[Calendar Day] 
     ).Item(0) 
     : 
     [Today] 
    } 
    MEMBER [Date].[Date - Calendar Month].[All].[ThisYear] AS 
    Aggregate([ThisYear]) 
    SET [LastYear] AS 
    { 
     Ancestor 
     (
      [TodayLstYr] 
     ,[Date].[Month Calendar].[Calendar Day] 
     ).Item(0) 
     : 
     [TodayLstYr] 
    } 
    MEMBER [Date].[Date - Calendar Month].[All].[LastYear] AS 
    Aggregate([LastYear]) 
SELECT 
    NON EMPTY 
    { 
     [Today] 
    ,[Date].[Date - Calendar Month].[All].[ThisYear] 
    ,[Date].[Date - Calendar Month].[All].[LastYear] 
    } ON COLUMNS 
,NON EMPTY 
     [Product].[Prod Name].[Prod Name].ALLMEMBERS 
    * 
     [Product].[Product].[Product].ALLMEMBERS ON ROWS 
FROM [Table] 
WHERE 
    [Measures].[Sell In Return]; 
0

ここでそれを得るためのもう一つのアプローチです:

with set Today as //today's date 
filter([Date].[Month Calendar].[Date].members, 
    Format([Date].[Month Calendar].currentmember.member_name, "Short Date") = 
format(now(), "Short Date")) 

set MonthBegToToday as //range of dates from current month's beginning till today 
{today.item(0).firstsibling : today.item(0)} 

set LastYearMonthBegToToday as //range of dates from current month's beginning till today (using parallelperiod function to get the "same date last year") 
PARALLELPERIOD([Date].[Month Calendar].[Year], 1, 
today.item(0).firstsibling) 
: 
PARALLELPERIOD([Date].[Month Calendar].[Year], 1, 
today.item(0)) 

member Measures.SalesMonthBegToToday as //total sales by using SUM() 
sum(MonthBegToToday, [Measures].[Sell In Return]) 

member Measures.SalesLastYearMonthBegToToday as 
sum(LastYearMonthBegToToday, [Measures].[Sell In Return]) 
0

は、私がメンバーと2つの期間を定義ヘルプ

をありがとうと列に範囲を追加する

WITH 

    MEMBER [Measures].[Key for Today] AS Format (Now() ,'yyyyMMdd' ) 
    member [measures].[CurrentYear] as Format (Now() ,'yyyy') 
    MEMBER [Measures].[TodayPrevYear] AS Format (DateAdd("YYYY",-1,Now()) ,'yyyyMMdd') 
Member [measures].[PrevYear] as Format (dateadd("YYYY",-1,Now()) ,'yyyy') 

SELECT 
    NON EMPTY 
    { 
     StrToMember ('[Date].[Date Key].[Date Key].&[' +[measures].[PrevYear]+'0101'+ ']',constrained) 
    :StrToMember ('[Date].[Date Key].[Date Key].&[' + [Measures].[TodayPrevYear] + ']',constrained) 
    , 
    StrToMember ('[Date].[Date Key].[Date Key].&[' +[measures].[CurrentYear]+'0101'+ ']',constrained) 
    :StrToMember ('[Date].[Date Key].[Date Key].&[' + [Measures].[Key for Today] + ']',constrained) 


    } ON COLUMNS 
,NON EMPTY 

     [Product].[Product].[Product].ALLMEMBERS 
     * [Product].[SKUs].[SKU].ALLMEMBERS 

     ON ROWS 
FROM [Table] 
WHERE 
    [Measures].[Sell In Return]; 
+0

私たちの答えを "アップ"することができます – whytheq

関連する問題