开发者

IIF in With Member comparing dates

开发者 https://www.devze.com 2023-02-26 20:00 出处:网络
I am very new to MDX and have a basic question. I would like a calculated measure which returns one value for dates less than a specified date, and another value if greater than a specified date. I ha

I am very new to MDX and have a basic question. I would like a calculated measure which returns one value for dates less than a specified date, and another value if greater than a specified date. I have attempted:

with member [开发者_如何转开发measures].[tempmeasure] as 
    IIF
       (
        [Date].[Date].CurrentMember < [Date].[Date].&[20100501]
        , 1
        , 2
       )

select 
   [Date].[Date].Members
   * 
   [measures].[tempmeasure] on columns
from [MyCube]

And this does not seem to work. That is using MS SSAS 2008. Any ideas what I could be doing wrong?


With:

IIF([Date].[Date].CurrentMember < [Date].[Date].&[20100501], 1, 2)

you're comparing two tuple values and not the date members themselves. You can have a look here for a tutorial on tuples, sets, etc...

As you're using AS, I think you can use the DataDiff function to compute the number of days between your two dates:

DateDiff("d", [Date].[Date].CurrentMember.MemberValue, [Date].[Date].&[20100501].MemberValue )

Otherwise, you may have some member properties available for that purpose:

IIF([Date].[Date].CurrentMember.Properties( 'prop-name', TYPED ) < [Date].[Date].&[20100501].Properties( 'prop-name', TYPED ) , 1, 2)

Cheers.


Please use below expression

IIF
   (
    [Date].[Date].Currentmember.MemberValue  < 
    [Date].[Date].&[20100501].MemberValue
    , 1
    , 2
   )

I have tested it is working as expected.....

Please let me know if you have any questions


IIF expects a logical expression which returns a boolean value. I think in your case [Date].[Date].CurrentMember will return a dimension value, a set. Less than operator in this case will cause a syntax error.

0

精彩评论

暂无评论...
验证码 换一张
取 消