Monday, March 19, 2012

calculate age from DOB Calculated measure

Hi All,

I am trying to calculate age from DOB and make it a calculated member.

With Member [Measures].[memberage] as

'datediff("yyyy",[Member].[DOB].[DOB],Now()) '

select {[Measures].[memberage]} on columns,

{[Member].[First Name]} on rows

from Cube

When i run this the memberage is returned as 2006 for all the DOB.

How do we calculate the age from DOB(datetime) and make it available as a calculated measure?

Thanks,

Awaiting your replies

Try

With Member [Measures].[memberage] as

'datediff("yyyy",[Member].[DOB].CurrentMember.MemberValue,Now()) '

select {[Measures].[memberage]} on columns,

{[Member].[First Name]} on rows

from Cube

|||

Hi

when i execute the above i get the following error

#Error Execution of the managed stored procedure datediff failed with the following error: Exception has been thrown by the target of an invocation.Argument 'Date1' cannot be converted to type 'Date'..

|||You have to provide an argument of type Date to DateDiff. I don't know the exact type of your [DOB] attribute. If MemberValue doesn't work in your case, you can try something like CDate([DOB].CurrentMember.Name). You need to somehow extract a Date value from the currentmember of the [DOB] hierarchy and pass it to DateDiff.

No comments:

Post a Comment