我正在尝试在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中如何做到这一点?维度使用应如何在维度和事实表之间建立关系以执行过滤。 附上截图
答案 0 :(得分: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]
)
尝试交换NonEmpty函数的Exists函数:
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]
)