MDX获取值并在层次结构上使用它

时间:2015-09-04 14:32:24

标签: mdx

我有一个MDX脚本,我的目标是能够获得日期,星期,月,季度或年份的日期值,然后在层次结构中使用它。

WITH 
  MEMBER measures.suma AS 
    Sum
    (
      [Date Local].[year-quarter-month-week-day].Children
     ,IIF
      (
            (
                  [Measures].[Agent Time Logged in hh:mm:ss]
                - 
                  [Measures].[Activity Time Break]
              - 
                [Measures].[Activity Time Meeting]
            - 
              [Measures].[Activity Time Training]
            )
          / 
            26400 / 86400
        > 1
       ,1
       ,
          (
                [Measures].[Agent Time Logged in hh:mm:ss]
              - 
                [Measures].[Activity Time Break]
            - 
              [Measures].[Activity Time Meeting]
          - 
            [Measures].[Activity Time Training]
          )
        / 
          26400 / 86400
      )
    ) 
SELECT 
  {
    measures.suma
   ,[Measures].[MyKeys]
   ,[Measures].[Agent Time Logged in hh:mm:ss]
   ,[Measures].[Activity Time Break]
   ,[Measures].[Activity Time Meeting]
   ,[Measures].[Activity Time Training]
   ,[Measures].[Activity time Lunch]
  } ON 0
 ,NON EMPTY 
    [Agent].[login fullname].[login fullname] ON 1
FROM [HP TRANSACTIONAL]
WHERE 
  [Date Local].[Month].&[2015-08 August];-- DOESNT WORK
--[Date Local].[year-quarter-month-week-day].[Week].&[2015 Week 35] --IT WORKS

正如您在我的MDX script中所看到的,我想总结代理商的所有活动,客户可以选择任何过滤器,每天,每周,每月,每季度或每年。
当然,可以使用我的层次结构“[Date Local]。[Month]。& [2015-08 August]”但我的客户正在使用EXCEL创建报告,他们可以使用日期的任何属性尺寸。

所以我的目标是找到一种向我的mdx脚本指示如果客户端选择任何属性,应该能够获取当前成员并使用层次结构进行计算的方法。

2 个答案:

答案 0 :(得分:0)

也许只需尝试使用关键字Existing来尝试强制上下文进入您的度量suma

   WITH 
      MEMBER [measures].[suma] AS 
        Sum
        (
          EXISTING([Date Local].[year-quarter-month-week-day].MEMBERS)
         ,IIF
          (
                (
                      [Measures].[Agent Time Logged in hh:mm:ss]
                    - 
                      [Measures].[Activity Time Break]
                  - 
                    [Measures].[Activity Time Meeting]
                - 
                  [Measures].[Activity Time Training]
                )
              / 
                26400 / 86400
            > 1
           ,1
           ,
              (
                    [Measures].[Agent Time Logged in hh:mm:ss]
                  - 
                    [Measures].[Activity Time Break]
                - 
                  [Measures].[Activity Time Meeting]
              - 
                [Measures].[Activity Time Training]
              )
            / 
              26400 / 86400
          )
        ) 
    SELECT 
      {
        measures.suma
       ,[Measures].[MyKeys]
       ,[Measures].[Agent Time Logged in hh:mm:ss]
       ,[Measures].[Activity Time Break]
       ,[Measures].[Activity Time Meeting]
       ,[Measures].[Activity Time Training]
       ,[Measures].[Activity time Lunch]
      } ON 0
     ,NON EMPTY 
        [Agent].[login fullname].[login fullname] ON 1
    FROM [HP TRANSACTIONAL]
    WHERE 
      [Date Local].[Month].&[2015-08 August];-- DOESNT WORK
    --[Date Local].[year-quarter-month-week-day].[Week].&[2015 Week 35] --IT WORKS

答案 1 :(得分:0)

我找到了解决方案!!

WITH 
  MEMBER measures.suma AS 
    Sum
    (
      (EXISTING 
        [Date Local].[year-quarter-month-week-day].[Day name])
     ,IIF
      (
            (
                  [Measures].[Agent Time Logged in hh:mm:ss]
                - 
                  [Measures].[Activity Time Break]
              - 
                [Measures].[Activity Time Meeting]
            - 
              [Measures].[Activity Time Training]
            )
          / 
            26400 / 86400
        > 1
       ,1
       ,
          (
                [Measures].[Agent Time Logged in hh:mm:ss]
              - 
                [Measures].[Activity Time Break]
            - 
              [Measures].[Activity Time Meeting]
          - 
            [Measures].[Activity Time Training]
          )
        / 
          26400 / 86400
      )
    ) 
SELECT 
  {
    measures.suma
   ,[Measures].[Agent Time Logged in hh:mm:ss]
   ,[Measures].[Activity Time Break]
   ,[Measures].[Activity Time Meeting]
   ,[Measures].[Activity Time Training]
   ,[Measures].[Activity time Lunch]
  } ON 0
 ,NON EMPTY 
    [Agent].[login fullname].[login fullname] ON 1
FROM [HP TRANSACTIONAL]
WHERE 
  [Date Local].[Date Standard].&[2015-08-24T00:00:00];
--TEST
--[Date Local].[Week].&[2015 Week 35]
--[Date Local].[Month].&[2015-08 August] 
--[Date Local].[year-quarter-month-week-day].[Week].&[2015 Week 35] 

我希望这个解决方案可以帮助其他人。 劳尔