问题
I am working with a SSAS 2008 R2 cube and interrogating the data through Excel 2010. In the cube I have a calculation to conditionally format the data. The logic is if a measure contains a specific value for the fact being viewed, then the fact should be colored red, as follows:
CALCULATE;
SCOPE
(
[Measures].[Data value]
);
If([Fact Base].[Confidentiality Status].[Confidential]) Then
Fore_Color(This) = 255
End If;
END SCOPE;
When I have a [Data value] of 0 (zero) the fore_color doesn't render as red in Excel
. If I change the data value to anything other than zero, and reprocess the cube it renders as Red. Is there something I'm missing, or is there a better MDX
script that would also work for values of zero?
回答1:
Effectively you have the following:
If([Fact Base].[Confidentiality Status].[Confidential] = 1) Then
Fore_Color(This) = 255
End If;
(... so wouldn't expect 0
to render as red?)
Does the following mean data 0
is red?:
If([Fact Base].[Confidentiality Status].[Confidential] = 0) Then
Fore_Color(This) = 255
End If;
回答2:
You should use
SCOPE
(
[Measures].[Data value], [Fact Base].[Confidentiality Status].[Confidential]
);
Fore_Color(This) = 255
END SCOPE;
Alternatively, but less efficient:
SCOPE
(
[Measures].[Data value]
);
If([Fact Base].[Confidentiality Status].CurrentMember IS [Fact Base].[Confidentiality Status].[Confidential]) Then
Fore_Color(This) = 255
End If;
END SCOPE;
This sets the foreground color for the measure Data value
and the Confidential
member.
What your code does is setting the foreground color if, for the Confidential
member, the value of the current measure (which is always Data value
within the SCOPE) is not null or 0. When evaluating a numeric expression as a condition, in MDX everything not 0 or null is evaluated as true. And if you are using a member here, MDX checks its value for the current measure. To check if the current member of a hierarchy is a specific one, you use IS
as I did in my second version above.
EDIT As the requirement is to check if in the current cell, there is data contained which is related to the confidentiality status "Confidential", no matter if that dimension is contained in the query or not, you can use:
SCOPE
(
[Measures].[Data value]
);
If(Intersect(EXISTING [Fact Base].[Confidentiality Status].[Confidentiality Status].Members,
{[Fact Base].[Confidentiality Status].[Confidential]}).Count = 1 Then
Fore_Color(This) = 255
End If;
END SCOPE;
This checks if the intersection between all members of the Confidentiality Status
level of the Confidentiality Status
attribute hierarchy that exist with the data of the current cell and the one element set consisting of the Confidential
member has one element, with other words, if the member is contained in the existing members of the level.
来源:https://stackoverflow.com/questions/26457478/calculation-in-ssas-cube-not-working-for-zero-data-values