我有[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]
我自己解决了。下面的代码完成了这项工作:
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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句