mdx 查询中最近三个月的最小值

Minimal value in last three months in mdx query

我正在尝试编写 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] }
      );

returns 出现以下错误: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 的新手所以请原谅我愚蠢的问题。

我给了自己一些时间思考这个问题,然后我解决了它。解决方法如下:

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] }
      );