我[Measures].[Days in the period]
计算Time
层次结构的天数。
我想创建一个计算成员,该成员将返回到今天为止的天数。例如,如果今天是11月14日,它必须显示11月的14天(而不是30天)。并且即将到来的几个月(例如,12月)为空。没有像SQL中的GetDate(),所以我对实现它的简单方法感到困惑。我的初始代码没有多少:
member [Measures].[Days in the period passed] as [Measures].[Days in the period]
答案 0 :(得分:1)
我自己解决了。下面的代码完成了这项工作:
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
编辑:更优雅,更正确的方式是范围:
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;
检查选择:
SELECT
([Time].[Calendar].[Mouth]) ON COLUMNS,
(([Measures].[Days in the period passed])) ON ROWS
FROM [TestCube]