MDX - Converting Member Value to CDate

2019-08-08 05:46发布

I need to convert a member value from this format dd.MM.yyyy into a CDate.
This was my trial:

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

However, I get a type mismatch error, because the format function ist not working properly.
I'm using a Microsoft Analysis Server.

Do someone know a solution for this issue?

1条回答
唯我独甜
2楼-- · 2019-08-08 06:14

You need to create a measure when to extract the date.

Here is a possible route:

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]
查看更多
登录 后发表回答