MDX - 提取最近24小时的数据

时间:2014-09-29 08:45:43

标签: ssas mdx

我需要从多维数据集中提取最近24小时的数据。下面是我编写的MDX,但它不会根据当前时间(系统时间)返回数据。

SELECT 
  [Date].[Calender-Year_Quarter_Month_Date].[Date] ON ROWS
 ,{[Measures].[Delay In Mintues]} ON COLUMNS
FROM 
(
  SELECT 
      {
          StrToMember
          ("[Date].[Calender-Year_Quarter_Month_Date].[Date].&["
              + 
                Format
                (
                  Now() - 1
                 ,'yyyyMMdd'
                )
            + "]"
          )
        * 
          (
            [Time].[Time-Hour_Time].[Hour].&["+FORMAT(NOW(),"HH")+"]
          : 
            [Time].[Time-Hour_Time].[Hour].&[23].&[23:59]
          )
      }
    + 
      {
          StrToMember
          ("[Date].[Calender-Year_Quarter_Month_Date].[Date].&["
              + 
                Format
                (
                  Now()
                 ,'yyyyMMdd'
                )
            + "]"
          )
        * 
          (
            [Time].[Time-Hour_Time].[Hour].&[0].&[00:00]
          : 
            [Time].[Time-Hour_Time].[Hour].&["+FORMAT(NOW(),"HH")+"]
          )
      } ON COLUMNS
  FROM [Delay Reasons]
);

1 个答案:

答案 0 :(得分:0)

(注意:未经测试)

这有用吗?

SELECT 
  [Date].[Calender-Year_Quarter_Month_Date].[Date] ON ROWS
 ,{[Measures].[Delay In Mintues]} ON COLUMNS
FROM [Delay Reasons]
WHERE 
    {
        StrToMember
        ("[Date].[Calender-Year_Quarter_Month_Date].[Date].&["
            + 
              Format
              (
                Now() - 1
               ,'yyyyMMdd'
              )
          + "]"
        )
      * 
        (
          [Time].[Time-Hour_Time].[Hour].&["+FORMAT(NOW(),"HH")+"]
        : 
          [Time].[Time-Hour_Time].[Hour].&[23].&[23:59]
        )
    }
  + 
    {
        StrToMember
        ("[Date].[Calender-Year_Quarter_Month_Date].[Date].&["
            + 
              Format
              (
                Now()
               ,'yyyyMMdd'
              )
          + "]"
        )
      * 
        (
          [Time].[Time-Hour_Time].[Hour].&[0].&[00:00]
        : 
          StrToMember
          (
            "[Time].[Time-Hour_Time].[Hour].&[" + Format(Now(),"HH") + "].&[00:00]"
          )
        )
    };