MDX - 将会员价值转换为CDate

时间:2015-09-09 15:58:43

标签: date string-formatting mdx olap

我需要将此格式dd.MM.yyyy的成员值转换为CDate 这是我的试用期:

cdate(format([Date].[Date].CURRENTMEMBER.MEMBER_VALUE, "dd.MM.yyyy"))
资料来源:http://www.datazen.com/blogs/post/working-with-dates-in-datazen-3-0

但是,我遇到类型不匹配错误,因为格式化功能无法正常工作 我正在使用Microsoft Analysis Server。

有人知道这个问题的解决方案吗?

1 个答案:

答案 0 :(得分:1)

您需要在何时提取日期时创建一个度量。

这是一条可能的路线:

MEMBER [Measures].[Date as int] as
       [Date].[Date].CURRENTMEMBER.Properties('Key0', Typed)
MEMBER [Measures].[Date Year] as
       Fix([Measures].[Date as int] / 10000)
MEMBER [Measures].[Date Month] as
       Fix(([Measures].[Date as int] - [Measures].[Date Year] * 10000) / 100)
MEMBER [Measures].[Date Day] as
       [Measures].[Date as int] - [Measures].[Date Year] * 10000 - [Measures].[Date Month] * 100

MEMBER [Measures].[DateValue_attempt1] as
       // convert it to Date data type and use a format string on that:
       DateSerial([Measures].[Date Year], [Measures].[Date Month], [Measures].[Date Day]),
       format_string = 'dd.MM.yyyy'
MEMBER [Measures].[DateValue_attempt2] as
       //if above fails maybe just convert it to string & do further conversion in client
       [Measures].[Date Day] + "." +
          [Measures].[Date Month] + "." +
             [Measures].[Date Year]