2016-11-03 15 views
0

私はクエリに渡されたパラメータを使用して現在の月&年の日付SSRSレポートに日付と年に月を構築するクエリを持っています。問題は、非常に多くの顧客、部品番号などがあるために、クエリが実行に時間がかかりすぎることです。より良いクエリを書いたり、それをスピードアップする方法はありますか?申し訳ありませんが、私は非常にこれに新しいです。以下は、クエリがある...スローMDXクエリ

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] 
    ) 
    MEMBER [Measures].[Sales Amount MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Sales Amount] 
    ) 
    MEMBER [Measures].[Sales Amount YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Sales Amount] 
    ) 
    MEMBER [Measures].[Cost Amount MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Cost Amount - Sales] 
    ) 
    MEMBER [Measures].[Cost Amount YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Cost Amount - Sales] 
    ) 
    MEMBER [Measures].[Sales Margin MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Sales Margin] 
    ) 
    MEMBER [Measures].[Sales Margin YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Sales Margin] 
    ) 
MEMBER [Measures].[Forecast Quantity MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Quantity] 
    ) 
    MEMBER [Measures].[Forecast Quantity YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Quantity] 
    ) 
    MEMBER [Measures].[Forecast Turnover MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Total Turnover] 
    ) 
    MEMBER [Measures].[Forecast Turnover YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Total Turnover] 
    ) 
    MEMBER [Measures].[Forcast Cost MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Total Cost] 
    ) 
    MEMBER [Measures].[Forecast Cost YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Total Cost] 
    ) 
    MEMBER [Measures].[Forecast Margin MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Margin] 
    ) 
    MEMBER [Measures].[Forecast Margin YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Forecast Margin] 
    ) 
    MEMBER [Measures].[Budget Quantity MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Budget Quantity] 
    ) 
    MEMBER [Measures].[Budget Quantity YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
    ,[Measures].[Budget Quantity] 
    ) 
    MEMBER [Measures].[Budget Turnover MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Total Turnover] 
    ) 
    MEMBER [Measures].[Budget Turnover YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Total Turnover] 
    ) 
    MEMBER [Measures].[Budget Cost MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Total Cost] 
    ) 
    MEMBER [Measures].[Budget Cost YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Total Cost] 
    ) 
    MEMBER [Measures].[Budget Margin MTD] AS 
    Sum 
    (
     MTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Margin] 
    ) 
    MEMBER [Measures].[Budget Margin YTD] AS 
    Sum 
    (
     YTD([Date].[Dates].CurrentMember) 
     ,[Measures].[Budget Margin] 
    ) 
SELECT 
    { 
    [Measures].[Quantity Shipped MTD], 
    [Measures].[Sales Amount MTD], 
    [Measures].[Cost Amount MTD], 
    [Measures].[Sales Margin MTD], 
    [Measures].[Margin %], 
    [Measures].[Forecast Quantity MTD], 
    [Measures].[Forecast Turnover MTD], 
    [Measures].[Forcast Cost MTD], 
    [Measures].[Forecast Margin MTD], 
    [Measures].[Margin %], 
    [Measures].[Budget Quantity MTD], 
    [Measures].[Budget Turnover MTD], 
    [Measures].[Budget Cost MTD], 
    [Measures].[Budget Margin MTD], 
    [Measures].[Margin %], 
    [Measures].[Quantity Shipped YTD], 
    [Measures].[Sales Amount YTD], 
    [Measures].[Cost Amount YTD], 
    [Measures].[Sales Margin YTD], 
    [Measures].[Margin %], 
    [Measures].[Forecast Quantity YTD], 
    [Measures].[Forecast Turnover YTD], 
    [Measures].[Forecast Cost YTD], 
    [Measures].[Forecast Margin YTD], 
    [Measures].[Margin %], 
    [Measures].[Budget Quantity YTD], 
    [Measures].[Budget Turnover YTD], 
    [Measures].[Budget Cost YTD], 
    [Measures].[Budget Margin YTD], 
    [Measures].[Margin %] 
    } ON COLUMNS, 
    NON EMPTY { (
[Customer].[Customer].[Customer].ALLMEMBERS * 
[Customer Sales].[Summary Prod Group 1].[Summary Prod Group 1].ALLMEMBERS * 
[Customer Sales].[Vehicle Mode].[Vehicle Mode].ALLMEMBERS * 
[Customer Sales].[Part Number].[Part Number].ALLMEMBERS) } 
ON ROWS 
FROM (SELECT (STRTOSET(@SummaryProdGroup, CONSTRAINED)) ON COLUMNS 
FROM (SELECT (STRTOSET(@SalesSummaryCode, CONSTRAINED)) ON COLUMNS 
FROM (SELECT (STRTOSET(@BusinessType, CONSTRAINED)) ON COLUMNS FROM [Sales]))) 
Where((
StrToMember 
    (
     [Measures].[Today string],constrained 
    )), 
IIF(STRTOSET(@BusinessType, CONSTRAINED).Count = 1, STRTOSET(@BusinessType, CONSTRAINED), [Customer].[Business Type].currentmember), 
IIF(STRTOSET(@SalesSummaryCode, CONSTRAINED).Count = 1, STRTOSET(@SalesSummaryCode, CONSTRAINED), [Customer].[Sales Summary Code].currentmember)) 

ありがとうございました

私はあなたの WHERE句のうち、次のように移動しようとする誘惑されると思います
+0

本当に単純化してからセクションを追加しましたか?再実行し、別のビットを追加してから、ボトルネックがどこにあるかを調べるために再度実行しますか? – whytheq

+0

私が珍しいことの一つは、あなたの 'WHERE'節に' .currentmember'を使うことです。 – whytheq

答えて

0

StrToMember 
    (
     [Measures].[Today string],constrained 
    ) 

のでWITH句は、その後かもしれません次のように入力します。

WITH 
    MEMBER [Measures].[Key for Today] AS 
    Format 
    (
     Now(),'yyyyMMdd' 
    ) 
    MEMBER [Measures].[Today string] AS 
    '[Date].[Dates].[Day].&[' + [Measures].[Key for Today] + ']' 
    SET [today] AS 
    StrToSet([Measures].[Today string],constrained) 
    MEMBER [Measures].[Quantity Shipped MTD] AS 
    Sum 
    (
     MTD([today].ITEM(0)) 
    ,[Measures].[Quantity Shipped] 
    ) 
    MEMBER [Measures].[Quantity Shipped YTD] AS 
    Sum 
    (
     YTD([today].ITEM(0)) 
    ,[Measures].[Quantity Shipped] 
    ) 
    ... 
    ... 
+0

こんにちは。上記の提案を試してみましたが、元のスクリプトと同じ時間がかかりますが、あなたが提案した解決策以外の追加データを持ち込むことを除いては同じです。クエリを大幅に遅くしているのは、[Part Number]のクロスジョインです。それがなければ、クエリーは実行に5秒かかります。部品番号では、最大45分かかります。問題は、部品番号が最も重要であり、私たちはそれらの中の大部分をデータベースに持っています。 – GarethS