Question

I have [Measures].[Days in the period] which calculates number of days for my Time hierarchy.

I want to create the calculated member that will return number of days until today. For example, if today is 14 of November it must show 14 days for November (not 30). And nulls for upcoming months (December, for example). There is nothing like GetDate() from SQL, so I'm a bit confused about easy way to implement it. My initial code doesn't have much:

member [Measures].[Days in the period passed] as [Measures].[Days in the period] 
Was it helpful?

Solution

Resolved it myself. The code below does the job:

WITH
MEMBER [Measures].[Days in the period passed] AS 
FILTER 
(
Descendants([Time].[Calendar], [Time].[Calendar].[Day]),
[Time].[Day].Properties("Day key") <= FORMAT(NOW(), "yyyyMMdd")
).COUNT

EDIT: more elegant and correct way is the scope:

SCOPE
( 
[Measures].[Days in the period passed], [Time].[Day].[Day].Members
);   

THIS =  IIF([Time].[Day].CurrentMember.Properties( "Key0" ) <= FORMAT(NOW(), "yyyyMMdd"),
                        [Measures].[Days in the period],
                        NULL); 
END SCOPE; 

Checking select:

SELECT 
([Time].[Calendar].[Mouth]) ON COLUMNS,
(([Measures].[Days in the period passed])) ON ROWS
FROM [TestCube]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top