How to Get Current Year with MDX Query?

2019-09-07 12:40发布

问题:

I have little thing about MDX. Is there any way to get current year from the system/server with MDX query? I didn't have any dimension related to date or something like that.

Regards.

回答1:

Create a member and define it as 'YEAR(NOW())'

Member [Measures].[Current Year] as 'YEAR(NOW())'

Here is a more complete sample

-- The First Calculated member is the value of NOW()
WITH  MEMBER [Measures].[Full Date] as 'NOW()'
-- The Second Calculated Member is the Day part of the first calculated member.
MEMBER [Measures].[What Day] as 'DAY([Full Date])'
-- The Third Calculated Member is the Month part of the first calculated member.
MEMBER [Measures].[What Month] as 'MONTH([Full Date])'
-- The Fourth Calculated Member is the Year part of the first calculated member.
Member [Measures].[What Year] as 'YEAR([Full Date])'
SELECT
   {[Full Date],[What Day],[What Month],[What Year]} ON COLUMNS
FROM [Your Cube]


标签: mdx