4

Am having trouble in understanding how FILTER function works in MDX.

Here is my query which gets all the non-empty Internet Order Count values for all Sales Territory Countries across all the Calendar Years.

    SELECT 
    NON EMPTY 
    {
        Filter
        (
        {[Date].[Calendar].[Calendar Year].MEMBERS}
        ,
        [Measures].[Internet Order Count] > 0
        )
    } ON COLUMNS
    ,[Sales Territory].[Sales Territory].[Country].MEMBERS
ON ROWS
FROM [Adventure Works]
WHERE 
    [Measures].[Internet Order Count];

This gives me all the orders as I am filtering by 0 and the result is as shown below

                CY 2010,CY 2011,CY 2012,CY 2013,CY 2014
France,         1      ,140    ,359    ,"1,917",67
Germany,               ,175    ,339    ,"1,909",61
United Kingdom ,1      ,175    ,405    ,"2,377",73
Canada,         1      ,170    ,169    ,"2,856",179
United States,  5      ,770    ,867    ,"7,590",335
Australia,      6      ,786    ,"1,130","4,640",156

Am putting in the results in csv format as am having restrictions in uploading image currently. Am new to MDX and my goal is to filter this result set where Internet Order Count is greater than 180.

Hence I now modified the query to this -

SELECT 
  NON EMPTY 
    {
      Filter
      (
        {[Date].[Calendar].[Calendar Year].MEMBERS}
       ,
        [Measures].[Internet Order Count] > 180
      )
    } ON COLUMNS
 ,[Sales Territory].[Sales Territory].[Country].MEMBERS
ON ROWS
FROM [Adventure Works]
WHERE 
  [Measures].[Internet Order Count];

This one gave me the below output -

                CY 2011,CY 2012,CY 2013,CY 2014
France,         140    ,359    ,"1,917",67
Germany,        175    ,339    ,"1,909",61
United Kingdom ,175    ,405    ,"2,377",73
Canada,         170    ,169    ,"2,856",179
United States,  770    ,867    ,"7,590",335
Australia,      786    ,"1,130","4,640",156

Basically CY 2010 entries are filtered out whereas what I am expecting is not to have entry/blank values of (France,CY 2011),(Germany, CY 2011),(UK, CY 2011), (Canada, CY 2011) etc. and of course similarily for some entries belonging to CY 2014 with similar result.

I am using AdventureWorksDW2014 cube. How would I go about doing this?

4

2 回答 2

4

您只过滤 Internet 订单数超过 180 的年份,而不是国家维度。尝试这个:

SELECT 
    NON EMPTY [Date].[Calendar].[Calendar Year].MEMBERS ON COLUMNS,
    [Sales Territory].[Sales Territory].[Country].MEMBERS ON ROWS
FROM (
    SELECT
        Filter (
            (
                [Date].[Calendar].[Calendar Year].MEMBERS , 
                [Sales Territory].[Sales Territory].[Country].MEMBERS
            ),
            [Measures].[Internet Order Count] > 180
        ) ON 0
    FROM [Adventure Works]
)
WHERE 
    [Measures].[Internet Order Count]
于 2015-07-20T10:43:56.310 回答
3

您的第一个脚本实际上就是以下内容。不需要任何过滤器,因为它是一个计数,所以 <0 永远不会发生:

SELECT 
  NON EMPTY 
    [Date].[Calendar].[Calendar Year].MEMBERS ON 0
 ,[Sales Territory].[Sales Territory].[Country].MEMBERS ON 1
FROM [Adventure Works]
WHERE 
  [Measures].[Internet Order Count];

在我的旧版本中,AdvWrks结果如下:

在此处输入图像描述

AI其实认为你更追求以下:

WITH 
  MEMBER [Measures].[transformToNull] AS 
    IIF
    (
      [Measures].[Internet Order Count] <= 180
     ,null
     ,[Measures].[Internet Order Count]
    ) 
SELECT 
  NON EMPTY 
    {[Date].[Calendar].[Calendar Year].MEMBERS} ON COLUMNS
 ,[Sales Territory].[Sales Territory].[Country].MEMBERS ON ROWS
FROM [Adventure Works]
WHERE 
  [Measures].[transformToNull];

结果如下:

在此处输入图像描述

于 2015-07-20T11:23:00.983 回答