创建包含两个日期之间的年数的计算成员

时间:2015-01-26 13:23:13

标签: ssas mdx olap reportbuilder3.0

我有一个包含两个日期的多维数据集 - Date of BirthDate of Purchase。我想创建一个计算成员,根据这两个日期生成age in years。我已经可以在运行查询后在数据集中执行此操作但是我想包括所有空值,因为我有基于显示所有空白的布局以及"使用过的"值。

有人能给我一个如何在MDX中计算这个的示例,因为运行这两个日期集目前会导致内存问题。

1 个答案:

答案 0 :(得分:0)

基本理念。当给出两个日期时,这仅返回一个度量。

请根据您的需要进行修改。

With 
Member NumOfDays As
{[Date].[Calendar Month Date].[Date].&[19850101]:[Date].[Calendar Month Date].[Date].&[19870927]}.Count
Member TotalYears As NumOfDays/365
Member Years As Int(TotalYears)
Member YearParts As TotalYears - Years
Member TotalMonths As (YearParts * 12)
Member Months As Int(TotalMonths)
Member MonthParts As TotalMonths - Months
Member Days As Int(MonthParts * 30)
Member Age As CSTR(Years) + " years, " + CSTR(Months) + " months and " + CSTR(Days) + " days"

Select 
{NumOfDays, TotalYears, Years, YearParts, TotalMonths, Months, MonthParts, Days, Age}

On 0
From [Adventure Works]

输出应如下所示。

enter image description here