3

我正在尝试在 mdx 中执行两个日期之间(包括)。我有两个事实表和一个映射表。

Fact_TableA 
  TableAId,
  ValueA,
  Date_FK

Fact_TableB
  TableBId,
  ValueB,
  Date_FK

Fact_MappingTable
 TableAId,
 TableBId

Fact_MappingTable 与 Fact_TableA 和 Fact_TableB 有多对多的关系。我在下面写了查询

 SELECT 
 NON EMPTY 
 { 
    [Measures].[ValueA], 
    [Measures].[ValueB] 
 } ON COLUMNS, 
 NON EMPTY 
 { 
    (
     [Fact Table A].[Column AID].[Column AID].ALLMEMBERS * 
     [Fact Table B].[Date FK].[Date FK].ALLMEMBERS 
     ) 
 } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM 
 (
    select ([Fact Mapping Table].[Date FK].&[2014-12-10T00:00:00] : [Fact Mapping Table].[Date FK].&[2015-01-01T00:00:00]) ON COLUMNS FROM [DW Testing] 
 )

此查询正在执行

Select 
   Fact_TableA.ValueA
  ,Fact_TableB.ValueB 
from 
   Fact_TableA 
   left outer join Fact_MappingTable on 
     Fact_TableA.TableAId = Fact_MappingTable.TableAId 
   left outer join Fact_TableB on 
     Fact_TableB.TableBId = Fact_MappingTable.TableBId
where Date_FK between '2015-01-01' and '2015-01-01'

但我的要求是

 Select 
   Fact_TableA.ValueA
  ,Fact_TableB.ValueB 
 from 
    Fact_TableA 
    left outer join Fact_MappingTable on 
      Fact_TableA.TableAId = Fact_MappingTable.TableAId and 
      Fact_MappingTable.DateM_FK between '2015-01-01' and '2015-01-10'
    left outer join Fact_TableB on 
    Fact_TableB.TableBId = Fact_MappingTable.TableBId
  where Date_FK between '2015-01-01' and '2015-01-10' 

我已尝试执行 Subselect 和 Where 切片器,但无法正常工作。有什么建议可以在 MDX 中完成吗?维度使用应该如何在维度和事实表之间建立关系以执行过滤。附上截图

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

也许是这样:

 SELECT 
 NON EMPTY 
 { 
    [Measures].[ValueA], 
    [Measures].[ValueB] 
 } ON COLUMNS, 
 NON EMPTY 
 { 
     EXISTS(
        [Fact Table A].[Column AID].[Column AID].ALLMEMBERS
       ,{[Fact Mapping Table].[Date FK].&[2014-12-10T00:00:00] 
          : 
         [Fact Mapping Table].[Date FK].&[2015-01-01T00:00:00])}
     ) 
     * [Fact Table B].[Date FK].[Date FK].ALLMEMBERS 
 } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM 
 (
    select ([Fact Mapping Table].[Date FK].&[2014-12-10T00:00:00] : [Fact Mapping Table].[Date FK].&[2015-01-01T00:00:00]) ON COLUMNS FROM [DW Testing] 
 )

尝试将 Exists 函数替换为 NonEmpty 函数:

SELECT 
 NON EMPTY 
 { 
    [Measures].[ValueA], 
    [Measures].[ValueB] 
 } ON COLUMNS, 
 NON EMPTY 
 { 
     NonEmpty(
        [Fact Table A].[Column AID].[Column AID].ALLMEMBERS
       ,{[Fact Mapping Table].[Date FK].&[2014-12-10T00:00:00] 
          : 
         [Fact Mapping Table].[Date FK].&[2015-01-01T00:00:00])}
     ) 
     * [Fact Table B].[Date FK].[Date FK].ALLMEMBERS 
 } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM 
 (
    select ([Fact Mapping Table].[Date FK].&[2014-12-10T00:00:00] : [Fact Mapping Table].[Date FK].&[2015-01-01T00:00:00]) ON COLUMNS FROM [DW Testing] 
 )
于 2015-09-18T17:27:26.413 回答