SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Conditional Calculated Measures


Conditional Calculated Measures

Author
Message
Michael French
Michael French
SSC Veteran
SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)

Group: General Forum Members
Points: 292 Visits: 624
I am having an issue trying to add some conditional logic to a calculated measure. What I am trying to do is to account for a change in view formula prior to a certain date. The below MDX query produces the desired results.

with member [Measures].[Monthly Adjusted Cost] as
CASE
WHEN StrToVal([Calendar].[YearMonthLabel].CurrentMember.Name) < 201101
THEN [Measures].[Cost AMT]*0.95
ELSE [Measures].[Cost AMT]
END

select non empty [Calendar].[YearMonthLabel].[YearMonthLabel].Members on rows

, {[Measures].[Cost AMT], [Measures].[Monthly Adjusted Cost]} on columns

from [CostCube]


The question then becomes how to put the case statement into the actual Cube definition from the Calculations tab of the Cube Design for CostCube in Visual Studio. The forms that I have been trying end up with #value error saying I have an empty MDX Expression. The cube builds and does not produce an error.
Please, let me know if anyone knows how best to do this.
Thank you
Mackers
Mackers
SSC Veteran
SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)SSC Veteran (229 reputation)

Group: General Forum Members
Points: 229 Visits: 499
Try something like:

with member [Measures].[Monthly Adjusted Cost] as
IIF(Exists([Calendar].[YearMonthLabel].CurrentMember, {null:[Calendar].[YearMonthLabel].&[201101]}).COUNT > 0
, [Measures].[Cost AMT]*0.95
, [Measures].[Cost AMT])

select non empty [Calendar].[YearMonthLabel].[YearMonthLabel].Members on rows

, {[Measures].[Cost AMT], [Measures].[Monthly Adjusted Cost]} on columns

from [CostCube]


It may be simpler to add a scope statement in your cube rather than doing a calc

scope {null:[Calendar].[YearMonthLabel].&[201101]};

[Measures].[Cost AMT] = [Measures].[Cost AMT]*0.95;

end scope;

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search