MDX filtering by multiple dimension members

浪尽此生 提交于 2019-12-11 03:35:31

问题


Problem

I need to create a report which will list a number of accounts that match certain criteria - simulationDate, statisticPeriod, region.

Right now my query looks like this:

WITH MEMBER [Measures].[Count] as 1
SELECT [Measures].[Count] ON COLUMNS,
NON EMPTY 
Crossjoin(
[Account].[Account Number].ALLMEMBERS,
{[simulationDate].[day].&[10010101]},
{[statisticPeriod].[period].&[201201]},
{[region].[code].&[SO]}
)
ON COLUMNS
FROM [myWH]

Is this cross-dimensional filtering okay?


回答1:


This is slightly more modern using the * notation instead of the Crossjoin function:

WITH 
  MEMBER [Measures].[Count] AS 1 
SELECT 
  [Measures].[Count] ON COLUMNS
 ,NON EMPTY 
      [Account].[Account Number].ALLMEMBERS*
      {[simulationDate].[day].&[10010101]}*
      {[statisticPeriod].[period].&[201201]}*
      {[region].[code].&[SO]} ON COLUMNS
FROM [myWH];

I'm assuming that your custom measure [Measures].[Count] is just a place-holder?

This table will be very wide if you have that cross-join on COLUMNS but that might just be a typo:

WITH 
  MEMBER [Measures].[Count] AS 1 
SELECT 
  [Measures].[Count] ON COLUMNS, 
  NON EMPTY 
      [Account].[Account Number].ALLMEMBERS*
      {[simulationDate].[day].&[10010101]}*
      {[statisticPeriod].[period].&[201201]}*
      {[region].[code].&[SO]} ON ROWS
FROM [myWH];

You have added the keywords NON EMPTY in front of the rows cross-join. This is telling the processor to exclude any rows that are empty - empty for [Measures].[Count] ....but this measure is never empty it is always equal to 1. So the following without Non Empty should return exactly the same result:

WITH 
  MEMBER [Measures].[Count] AS 1 
SELECT 
  [Measures].[Count] ON COLUMNS, 
      [Account].[Account Number].ALLMEMBERS*
      {[simulationDate].[day].&[10010101]}*
      {[statisticPeriod].[period].&[201201]}*
      {[region].[code].&[SO]} ON ROWS
FROM [myWH];

So in terms of filtering you aren't doing any - what sort of filtering do you need? If you replace [Measures].[Count] with an actual measure from your cube and use the NON EMPTY then you should see a lot less rows:

SELECT 
  [Measures].[ReplaceWithActualMeasure] ON COLUMNS, 
  NON EMPTY
      [Account].[Account Number].ALLMEMBERS*
      {[simulationDate].[day].&[10010101]}*
      {[statisticPeriod].[period].&[201201]}*
      {[region].[code].&[SO]} ON ROWS
FROM [myWH];



回答2:


In the end I ended up using the filters as my columns, and letting the NON EMPTY clause take care of the filtering:

SELECT 
 NON EMPTY 
    {[simulationDate].[day].&[10010101]} *
    {[statisticPeriod].[period].&[201201]} *
    {[region].[code].&[SO]}
 ON COLUMNS,
 NON EMPTY
    [Account].[Account Number].ALLMEMBERS 
 ON ROWS
FROM [myWH]


来源:https://stackoverflow.com/questions/30940628/mdx-filtering-by-multiple-dimension-members

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