Mdx query incosistent with cube browser

白昼怎懂夜的黑 提交于 2019-12-14 02:29:48

问题


I have built a multidimensional SSAS cube with some calculations. I have a calculated member in which I use the the parallelperiod function to calculate the previous month value according to the following code :

Sum
(
  (EXISTING 
    [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[date].MEMBERS)
 ,(
    ParallelPeriod
    (
      [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[month]
     ,1
     ,[TimeDim Transactions].[Year -  Quarter -  Month -  Date].CurrentMember
    )
   ,[Measures].[Net Amount]
  )
)

When I run the following query it works as expected.

SELECT 
  {
    NetAmountSamePeriodLastMonth
   ,[Measures].[net amount]
  } ON COLUMNS
 ,[Stores Dim].[Store Code].Children ON ROWS
FROM [SalesDW_v1]
WHERE 
  {
    [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-04T00:00:00]
   ,[TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-05T00:00:00]
  };

But when I browse the cube to get the same data with the same date filters It gives wrong numbers. The generated from browser mdx script is :

SELECT 
  NON EMPTY 
    {
      [Measures].[Net Amount]
     ,[Measures].[NetAmountSamePeriodLastMonth]
    } ON COLUMNS
 ,NON EMPTY 
    {[Stores Dim].[Store Code].[Store Code].ALLMEMBERS}
  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME
   ON ROWS
FROM 
(
  SELECT 
    {
      [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-04T00:00:00]
     ,[TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-05T00:00:00]
    } ON COLUMNS
  FROM [SalesDW_v1]
)
WHERE 
  [TimeDim Transactions].[Year -  Quarter -  Month -  Date].CurrentMember
CELL PROPERTIES 
  VALUE
 ,BACK_COLOR
 ,FORE_COLOR
 ,FORMATTED_VALUE
 ,FORMAT_STRING
 ,FONT_NAME
 ,FONT_SIZE
 ,FONT_FLAGS;

Something more, the browser shows correct numbers when one date is selected.

Is there a way to modify the calculated member in order to work correctly at the browser. I present the data on a power view report, but what i get is the incorrect numbers I see at the browser.

Below the code generated by browser when I use only one date member :

SELECT 
  NON EMPTY 
    { [Measures].[Net Amount]
     ,[Measures].[NetAmountSamePeriodLastMonth] 
    } 

    ON COLUMNS 
    ,NON EMPTY 
    { ([Stores Dim].[Store Code].[Store Code].ALLMEMBERS ) } 
    DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME ON ROWS 

   FROM 
       ( 
        SELECT (
                {[TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-05T00:00:00] } 
               ) ON COLUMNS 

  FROM [SalesDW_v1]
       )
  WHERE ( [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-05T00:00:00] ) 
CELL PROPERTIES VALUE
, BACK_COLOR, FORE_COLOR
, FORMATTED_VALUE
, FORMAT_STRING
, FONT_NAME
, FONT_SIZE
, FONT_FLAGS

回答1:


The problem is that the scope(for [TimeDim Transactions] dimension) is not getting set correctly when you are having two dates in filter. But, in case of single date, the scope sets correctly, and hence the answer matches.

When one date is selected

See the clause associated with slicer. It is [TimeDim Transactions].[Year - Quarter - Month - Date].[Date].&[2014-12-05T00:00:00] )

When two dates are selected

The slicer becomes: [TimeDim Transactions].[Year - Quarter - Month - Date].CurrentMember

Note that a sub-select does not set a context. So when you say that you want to filter by [TimeDim Transactions].[Year - Quarter - Month - Date].CurrentMember, you are not actually filtering at all, since the current member ins absence of scope is the [All] member. That's why you are having a weirdly large figure.

To get rid of the issue, try having the dates in the axes, as below, instead of slicer, so that the scope gets selected.

 ,NON EMPTY 
    {[Stores Dim].[Store Code].[Store Code].ALLMEMBERS} * 
    {
      [TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-04T00:00:00]
     ,[TimeDim Transactions].[Year -  Quarter -  Month -  Date].[Date].&[2014-12-05T00:00:00]
    }

  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME
   ON ROWS


来源:https://stackoverflow.com/questions/28629181/mdx-query-incosistent-with-cube-browser

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