如何在mdx查询中的列上获取最小或最大日期

时间:2016-02-12 01:31:05

标签: date max mdx min

我可以为此示例实现什么mdx查询逻辑,以获得hrid = 1的结果集中的两行,其中1/1/16作为第一行的最小日期(开始),其中someattribut显示在具有值&#39的列上; A' 和1/15/16作为第二行的最小日期(开始),其中someattribute的值为' B'和measure.whatevers有对应于该维度行的任何数据的聚合。

我试着看看2016年1月

我试过的一切似乎都得到了1/1/1900的最小日期值,或者这两行的值都是1/1/2016,或者我得到了错误,因为我无法弄明白。

enter image description here

继承我的mdx样本:

WITH MEMBER [Measures].[Start] as 
  (
-- min date that the combination of someattribute and hrid have certain 
-- value withing the range of the where clause restriction of january 2016

SELECT { 
[Measures].[Start]
, [Measures].[Whatevers]
} ON COLUMNS
, NON EMPTY { 
[Agent].[HRID].children
* [Agent].[someAtribute].Members
} ON ROWS
FROM [RADM_REPORTING]
WHERE ( 
    [Date].[Date View].[Month].&[201601]
    )

2 个答案:

答案 0 :(得分:0)

这是一个更为通用的潜在方向:

WITH 
  MEMBER [Measures].[Start] AS 
    Min
    (
      (EXISTING 
        [Date].[Date].[Date].MEMBERS)
     ,IIF
      (
        [Measures].[Internet Sales Amount] = 0
       ,NULL
       ,[Date].[Date].CurrentMember.MemberValue
      )
    ) 
SELECT 
  NON EMPTY 
    {
      [Measures].[Start]
     ,[Measures].[Internet Sales Amount]
    } ON COLUMNS
 ,NON EMPTY 
    [Product].[Product Categories].[Product] ON ROWS
FROM [Adventure Works]
WHERE 
  [Date].[Calendar].[Calendar Year].&[2005];

它提供以下内容:

enter image description here

答案 1 :(得分:0)

this works, but it feels kind of like a hack or maybe it feels like its not robust, I am not familiar enough with mdx to be able to make that call.

WITH MEMBER [Measures].[Start] as 
 filter([Date].[Date View].[Month].&[201601].children, 
 [Measures].[Whatevers]).item(0).membervalue