【问题标题】:MDX Filter date less than todayMDX 过滤器日期小于今天
【发布时间】:2016-09-22 09:29:34
【问题描述】:

我想以某种方式在数据集中过滤我的查询,其中我得到了从月初到昨天的日期。第一部分很简单,我从报告参数中传递月份,所以我从每月的每一天得到值,但不知何故我必须将其限制到昨天。我尝试将此表达式放在 where 子句中,但它根本不起作用,因为我在行上没有日期:FILTER([Date of shipment].[Date], [Date of shipment].[Date] < Format(Now(), "yyyyMMdd")。 我知道我可以过滤行,但重要的是,我不希望 Date 显示在行上。

编辑:另外我可以使用主报告提供的参数,即昨天的日期。但是我如何限制日期而不把它放在行上?这样的东西不起作用:IIF( STRTOSET(@ShipmentDate, CONSTRAINED).Count = 1, STRTOSET(@ShipmentDate, CONSTRAINED), [Shipment Date].[Date] < @ShipmentDate))

【问题讨论】:

    标签: reporting-services ssas mdx business-intelligence ssas-2012


    【解决方案1】:

    你已经有类似的东西了:

    SELECT 
      {} ON 0
     ,
        [Date].[Calendar].[Date].&[20050101]
      : 
        StrToMember
        ('[Date].[Calendar].[Date].&[20050105]'   //<<hard-coded to illustrate 
         ,constrained
        ) ON 1
    FROM [Adventure Works];
    

    返回:

    大多数多维数据集具有多级日期层次结构 - 因此您可以将代码更改为类似的内容,以便明年您无需更改硬编码位:

    SELECT 
      {} ON 0
     ,
        Descendants
        (
          Exists
          (
            [Date].[Calendar].[Calendar Year].MEMBERS
           ,StrToMember
            (@ShipmentDate
             ,constrained
            )
          ).Item(0)
         ,[Date].[Calendar].[Date]
        ).Item(0)
      : 
        StrToMember
        (@ShipmentDate
         ,constrained
        ) ON 1
    FROM [Adventure Works];
    

    如果@ShipmentDate 设置为'[Date].[Calendar].[Date].&amp;[20060105]',那么我会得到以下信息:

    【讨论】:

    • 谢谢,这真的很好。我会使用你的解决方案。
    【解决方案2】:

    解决方案: 由于我通过参数日期传递了月份,因此仅限于当前月份。这让我可以这样做:

    [Shipment date].[Datw].&[20160101] : STRTOMEMBER(@ShipmentDate, constrained)
    

    我这样做的方式很丑陋,但它可以工作(它可能需要维护,明年将日期更改为 20170101 等等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多