2016-09-26 71 views
1

我試圖建立一個查詢將從一個多維數據集中檢索值,並在一個月建造日期和一年的基礎上,當前日期日期SSRS報告。基本上,我試圖建立一個報告,應該是這個樣子......MDX月初至今年初至今查詢

Type Customer Product Group Quantity Shipped MTD Quantity Shipped YTD 
===================================================================== 

OE CompanyX Bikes     5     396 
       Helmets     10    254 

    CompanyY Repair Kits    93    653 
       T-shirts     38    564 
       Shoes     10    120 

我真的爲此而努力,到目前爲止,這是我想出...

WITH 
MEMBER [Measures].[Quantity Shipped YTD] As Sum(YTD([Date].[Dates].CurrentMember),[Measures].[Quantity Shipped]) 
Member [Measures].[Quantity Shipped MTD] As Sum(MTD([Date].[Dates].CurrentMember),[Measures].[Quantity Shipped]) 
SELECT NON EMPTY { [Measures].[Quantity Shipped MTD], [Measures].[Quantity Shipped YTD] } ON COLUMNS, 
NON EMPTY { ([Customer].[Business Type].[Business Type].ALLMEMBERS * [Customer].[Customer].[Customer].ALLMEMBERS * [Customer Sales].[Summary Prod Group 1].[Summary Prod Group 1].ALLMEMBERS) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM (SELECT (-{ [Customer Sales].[Summary Prod Group 1].&[Missing Product Group] }) ON COLUMNS 
FROM (SELECT ({ [Customer].[Customer Code].&[2.254E3], [Customer].[Customer Code].&[2.063E3], [Customer].[Customer Code].&[2.183E3], [Customer].[Customer Code].&[2.261E3], [Customer].[Customer Code].&[5.3753E4], [Customer].[Customer Code].&[1.3084E5], [Customer].[Customer Code].&[1.37058E5] }) ON COLUMNS 
FROM (SELECT ({ [Customer].[Business Type].&[OE] }) ON COLUMNS 
FROM (SELECT ([Date].[Day].&[Now()]) ON COLUMNS 
FROM [Sales])))) WHERE ([Customer].[Customer Code].CurrentMember) 
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS 

上面的查詢不檢索雖然什麼。我得到的只是一個空白的結果集。還有很多更多的領域,我需要渡過難關,但我猜想,如果我能得到運工作的數量,我可以得到一切。請幫忙。 TX

+0

你有一個成員叫這個 ?! '[日期],[日]&[NOW()]' – whytheq

回答

0

目前你沒有任何日期in context這意味着currentmember不會被找到了 - 有個約會in context你需要一個實際的日期成員添加到您的WHERESELECT條款 - 而不是一個SELECT條款一個subselect

Now()是成員的不同尋常的名字,因爲它是一個VBA函數,但如果這真的是名字,那麼你可以將其移動到WHERE子句:

WITH 
    MEMBER [Measures].[Quantity Shipped YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Quantity Shipped] 
    ) 
    MEMBER [Measures].[Quantity Shipped MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Quantity Shipped] 
    ) 
SELECT 
    NON EMPTY 
    { 
     [Measures].[Quantity Shipped MTD] 
    ,[Measures].[Quantity Shipped YTD] 
    } ON COLUMNS 
,NON EMPTY 
    { 
     [Customer].[Business Type].[Business Type].ALLMEMBERS* 
     [Customer].[Customer].[Customer].ALLMEMBERS* 
     [Customer Sales].[Summary Prod Group 1].[Summary Prod Group 1].ALLMEMBERS 
    } ON ROWS 
FROM 
(
    SELECT 
    { 
     [Customer].[Customer Code].&[2.254E3] 
    ,[Customer].[Customer Code].&[2.063E3] 
    ,[Customer].[Customer Code].&[2.183E3] 
    ,[Customer].[Customer Code].&[2.261E3] 
    ,[Customer].[Customer Code].&[5.3753E4] 
    ,[Customer].[Customer Code].&[1.3084E5] 
    ,[Customer].[Customer Code].&[1.37058E5] 
    } ON 0 
    ,{[Customer].[Business Type].&[OE]} ON 1 
    ,- 
     { 
     [Customer Sales].[Summary Prod Group 1].&[Missing Product Group] 
     } ON 2 
    FROM [Sales] 
) 
WHERE 
    [Date].[Day].&[Now()]; 

我懷疑這[Date].[Day].&[Now()];是該成員的不是名字,你正在試圖做在這種情況下,你需要使用strToMember

我已經構造的東西在AdvWrks立方相媲美的東西研究動態:

WITH 
    MEMBER [Measures].[_YTD] AS 
    Aggregate 
    (
     YTD([Date].[Calendar].CurrentMember) 
    ,[Measures].[Order Quantity] 
    ) 
    MEMBER [Measures].[_MTD] AS 
    Aggregate 
    (
     MTD([Date].[Calendar].CurrentMember) 
    ,[Measures].[Order Quantity] 
    ) 
SELECT 
    { 
    [Measures].[_YTD] 
    ,[Measures].[_MTD] 
    } ON COLUMNS 
,[Product].[Category].Children ON ROWS 
FROM [Adventure Works] 
WHERE 
    [Date].[Calendar].[Date].&[20050805]; 

它返回:

enter image description here

如果我想使用VBA函數now()那麼這需要發生,使上述動態:

WITH 
    MEMBER [Measures].[Key for Today] AS 
    Format 
    (
     Now() 
    ,'yyyyMMdd' 
    ) 
    MEMBER [Measures].[Today string] AS 
    '[Date].[Calendar].[Date].&[' + [Measures].[Key for Today] + ']' 
    MEMBER [Measures].[_YTD] AS 
    Aggregate 
    (
     YTD([Date].[Calendar].CurrentMember) 
    ,[Measures].[Order Quantity] 
    ) 
    MEMBER [Measures].[_MTD] AS 
    Aggregate 
    (
     MTD([Date].[Calendar].CurrentMember) 
    ,[Measures].[Order Quantity] 
    ) 
SELECT 
    { 
    [Measures].[_YTD] 
    ,[Measures].[_MTD] 
    } ON COLUMNS 
,[Product].[Category].Children ON ROWS 
FROM [Adventure Works] 
WHERE 
    StrToMember 
    (
     [Measures].[Today string] 
    ,constrained 
    ) ; 
+0

謝謝你,謝謝你,謝謝你的sooo多!稍微調整一下,我就可以使腳本起作用。是的,我試圖使它動態,因此Now()函數。我將通過回答問題來粘貼用於報告的代碼。 – GarethS

+0

@GarethS樂趣 - 高興,這是幫助。 – whytheq

0

由於whytheq,這是我想出了什麼...

WITH 
    MEMBER [Measures].[Key for Today] AS 
    Format 
    (
     Now() 
    ,'yyyyMMdd' 
    ) 
    MEMBER [Measures].[Today string] AS 
    '[Date].[Dates].[Day].&[' + [Measures].[Key for Today] + ']' 

    MEMBER [Measures].[Quantity Shipped MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Quantity Shipped] 
    ) 
    MEMBER [Measures].[Quantity Shipped YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Quantity Shipped] 
    ) 

SELECT NON EMPTY 
    { 
    [Measures].[Quantity Shipped MTD], 
    [Measures].[Quantity Shipped YTD] 
    } ON COLUMNS, NON EMPTY 
    { 
    [Customer].[Business Type].[Business Type].ALLMEMBERS* 
    [Customer].[Customer].[Customer].ALLMEMBERS* 
    [Customer Sales].[Summary Prod Group 1].[Summary Prod Group 1].ALLMEMBERS} On Rows 
From 
(
    SELECT 
    { 
     [Customer].[Customer Code].&[2.254E3] 
    ,[Customer].[Customer Code].&[2.063E3] 
    ,[Customer].[Customer Code].&[2.183E3] 
    ,[Customer].[Customer Code].&[2.261E3] 
    ,[Customer].[Customer Code].&[5.3753E4] 
    ,[Customer].[Customer Code].&[1.3084E5] 
    ,[Customer].[Customer Code].&[1.37058E5] 
    } ON 0 
    ,{[Customer].[Business Type].&[OE]} ON 1 
    ,- 
     { 
     [Customer Sales].[Summary Prod Group 1].&[Missing Product Group] 
     } ON 2 
From [Sales]) 
Where 
StrToMember 
    (
     [Measures].[Today string] 
    ,constrained 
    )