问题
This is my code below......
SELECT
{
[Measures].[ACPPurchaseValue]
} ON COLUMNS
,(
[Date].[YYYYMMDD].[YYYYMMDD]
) ON ROWS
FROM [Kahuna]
WHERE
(
[Reporting Currency].[reportingCurrency].&[1]
,strToSet(@MdxBOSP)
,strToSet(@MdxVIPType)
,strToSet(@MdxHost)
,strToSet(@MdxOperatorName)
);
How can I say where [Date].[YYYYMMDD].[YYYYMMDD] < getdate()
回答1:
You need to initially create a member, or a single member set, that corresponds to today.
The following looks a little complex but is actually a fairly standard approach - put forward by Tomislav Piasevoli - it is against the AdvWrks
dimension Date
:
WITH
MEMBER [Measures].[Key for Today] AS
Format
(
Now()
,'yyyyMMdd'
)
MEMBER [Measures].[Today string] AS
'[Date].[Calendar].[Date].&[' + [Measures].[Key for Today] + ']'
SET [Today] AS
StrToMember
(
[Measures].[Today string]
,constrained
)
...
So applying to your situation:
WITH
MEMBER [Measures].[Key for Today] AS
Format
(
Now()
,'yyyyMMdd'
)
MEMBER [Measures].[Today string] AS
'[Date].[YYYYMMDD].[YYYYMMDD].&[' + [Measures].[Key for Today] + ']'
SET [Today] AS
StrToMember
(
[Measures].[Today string]
,constrained
)
SELECT
[Measures].[ACPPurchaseValue] ON 0
,{null:[Today].item(0).item(0)} ON 1
FROM [Kahuna]
WHERE
(
[Reporting Currency].[reportingCurrency].&[1]
,strToSet(@MdxBOSP)
,strToSet(@MdxVIPType)
,strToSet(@MdxHost)
,strToSet(@MdxOperatorName)
);
Two other better solutions which could simplify life for everyone:
Do not materialize future dates in your cube
Leave future dates in, but add a custom set called
[Today]
and a calculated member called today as a child to Date's All member.
来源:https://stackoverflow.com/questions/35479968/mdx-where-date-is-less-than-now