MDX 按日期过滤结果
MDX filtering results by date
我想过滤我的查询结果,因此它 return 仅当日期大于指定日期时才显示值。
我写了类似的东西:
SELECT { [Measures].[Net sales] } ON COLUMNS
FROM [Sales]
WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
{( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY >= '2015-10-10'))} );
但它 return 为空。没有这部分 filter()
它 return 是整个 [Net sales]
。
试试这个:
SELECT { [Measures].[Net sales] } ON COLUMNS
FROM [Sales]
WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
{( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY > '2015-10-10'))} );
也许是这样的:
WITH
MEMBER [Measures].[Net sales NEW] AS
SUM(
FILTER(
[Time].[Date].[Date].MEMBERS,
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
>= 20151010
)
, [Measures].[Net sales]
)
SELECT
{
[Measures].[Net sales]
,[Measures].[Net sales NEW]
} ON 0
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
另一种方法:
WITH
MEMBER [Measures].[Date_key] AS
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
MEMBER [Measures].[Net sales NEW] AS
SUM(
[Time].[Date].[Date].MEMBERS,
IIF(
[Measures].[Date_key] >= 20151010
, [Measures].[Net sales]
, NULL
)
)
SELECT
{
[Measures].[Net sales]
,[Measures].[Net sales NEW]
} ON 0
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
一个问题:这绝对是你的日期键的格式吗? '2015-10-10'
根据 WHERE 切片器检查密钥的一种可能的可视化方法是使用如下更简单的脚本:
WITH
MEMBER [Measures].[Date_key] AS
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
SELECT
[Measures].[Date_key] ON 0
[Time].[Date].[Date].MEMBERS ON 1
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
不确定以上内容有什么问题 - 我明天需要针对 AdvWrks 多维数据集进行测试。
另一种方法可能是:
SELECT
[Measures].[Net sales] } ON 0
FROM [Sales]
WHERE (
{ [Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT] }
, {[Time].[Date].[Date].&[10 Oct 2015]:null}
);
注意:您需要将 10 Oct 2015
更改为多维数据集中的格式,并且 10 Oct 2015
必须是多维数据集中存在的日期。
我想过滤我的查询结果,因此它 return 仅当日期大于指定日期时才显示值。
我写了类似的东西:
SELECT { [Measures].[Net sales] } ON COLUMNS
FROM [Sales]
WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
{( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY >= '2015-10-10'))} );
但它 return 为空。没有这部分 filter()
它 return 是整个 [Net sales]
。
试试这个:
SELECT { [Measures].[Net sales] } ON COLUMNS
FROM [Sales]
WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
{( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY > '2015-10-10'))} );
也许是这样的:
WITH
MEMBER [Measures].[Net sales NEW] AS
SUM(
FILTER(
[Time].[Date].[Date].MEMBERS,
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
>= 20151010
)
, [Measures].[Net sales]
)
SELECT
{
[Measures].[Net sales]
,[Measures].[Net sales NEW]
} ON 0
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
另一种方法:
WITH
MEMBER [Measures].[Date_key] AS
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
MEMBER [Measures].[Net sales NEW] AS
SUM(
[Time].[Date].[Date].MEMBERS,
IIF(
[Measures].[Date_key] >= 20151010
, [Measures].[Net sales]
, NULL
)
)
SELECT
{
[Measures].[Net sales]
,[Measures].[Net sales NEW]
} ON 0
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
一个问题:这绝对是你的日期键的格式吗? '2015-10-10'
根据 WHERE 切片器检查密钥的一种可能的可视化方法是使用如下更简单的脚本:
WITH
MEMBER [Measures].[Date_key] AS
[Time].[Date].CURRENTMEMBER.MEMBER_KEY
SELECT
[Measures].[Date_key] ON 0
[Time].[Date].[Date].MEMBERS ON 1
FROM [Sales]
WHERE {
[Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT]
};
不确定以上内容有什么问题 - 我明天需要针对 AdvWrks 多维数据集进行测试。
另一种方法可能是:
SELECT
[Measures].[Net sales] } ON 0
FROM [Sales]
WHERE (
{ [Department].[Department name].&[WRO]
, [Department].[Department name].&[KAT] }
, {[Time].[Date].[Date].&[10 Oct 2015]:null}
);
注意:您需要将 10 Oct 2015
更改为多维数据集中的格式,并且 10 Oct 2015
必须是多维数据集中存在的日期。