how to get min or max date on columns in mdx query

﹥>﹥吖頭↗ 提交于 2019-12-12 03:32:28

问题


what mdx query logic could i implement for this example to get two rows in result set for hrid = 1 with 1/1/16 as min date(start) for first row where someattribut shows up on column with value 'A' and 1/15/16 as min date(start) for second row where someattribute has value of 'B' and measure.whatevers has its aggregation for whatever data corresponds to that dimension row.

Im trying to just look at january 2016

everything ive tried i seem to get min date values of 1/1/1900 or both rows have value of 1/1/2016 or i get errors since i cant figure it out.

heres my mdx sample:

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

回答1:


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



回答2:


Here is a potential direction that is more general:

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

It gives the following:



来源:https://stackoverflow.com/questions/35353306/how-to-get-min-or-max-date-on-columns-in-mdx-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!