2016-04-11 55 views
0

我試圖編寫MDX查詢,選擇最近三個月的最低銷售價格的產品,但我不能得到它的工作。最近三個月在mdx查詢中的最小值

這是我的原型代碼是不工作:

WITH 
    SET [CurrentMonth] AS StrToMember('[Date].[Calendar].[Month].&[' + FORMAT(Now(), "yyyyMM") + ']') 
    SET [LastThreeMonths] AS TAIL({NULL: [CurrentMonth].ITEM(0)}, 3) 
SELECT 
    { 
     min(Tail([LastThreeMonths],3), iif([Measures].[Net sale price] = 0, null, [Measures].[Net sale price])) 
    } ON COLUMNS 
    ,{ 
     [Product].[Product code].MEMBERS 
    } ON ROWS 
FROM [Sales] 
WHERE ( 
     { [Department].[Department name].&[WRO] } 
    ); 

返回以下錯誤:function "" expects a tuple set expression for the 1 argument

如果我嘗試類似的東西:

WITH 
    SET [CurrentMonth] AS StrToMember('[Date].[Calendar].[Month].&[' + FORMAT(Now(), "yyyyMM") + ']') 
    SET [LastThreeMonths] AS TAIL({NULL: [CurrentMonth].ITEM(0)}, 3) 
SELECT 
    { 
     (Tail([LastThreeMonths],3), [Measures].[Net sale price]) 
    } ON COLUMNS 
    ,{ 
     [Product].[Product Code].MEMBERS 
    } ON ROWS 
FROM [Sales] 
WHERE ( 
     { [Department].[Department name].&[WRO] } 
    ); 

它的工作原理但這不是我想要的 - 它顯示了過去三個月的每個月的淨銷售價格。 我是MDX的新手,所以請原諒我愚蠢的問題。

+0

這不是從你的問題清楚:你想在過去的三個月每個最後三個月的_single_最小值,或_separate_最小值?請編輯該問題以澄清此問題。 – SebTHU

+0

@Dodzik,所以我認爲你的魔方必須包含未來的幾個月? (我們的立方體不包含未來的日期) – whytheq

+0

@whytheq你是什麼意思? – Dodzik

回答

0

我給了我一些時間來思考,並解決了這個問題。這裏的解決方案:

WITH 
    SET [Current month] AS StrToMember('[Date].[Calendar].[Month].&[' + FORMAT(Now(), "yyyyMM") + ']') 
    SET [Last three months] AS LastPeriods(3, [Current month].item(0)) 
    MEMBER [Min price] AS MIN([Last three months], [Measures].[Net sale price]) 
SELECT 
    { 
     [Min price] 
    } ON COLUMNS 
    ,{ 
     [Product].[Product name].MEMBERS 
    } ON ROWS 
FROM [Sales] 
WHERE ( 
     { [Department].[Department name].&[WRO] } 
    );