开发者

Using SSRS expression as a variable

I am trying to use a expression within an expression in SSRS and it's getting really complicated. Is there a way around this?

For example if I have a number of sales and number of contacts I can create the conversion rate by dividing the sales开发者_运维问答 into the contacts ie

=fields!sales.value/fields!contacts.value

What I want to do next is use this to put the sales people into various bands so that those with a conversion rate in thresholds are displayed in bandings.

=iif(fields!sales.value/fields!contacts.value<0.5,"poor","Ok")

This is fine for 2 bandings (ok and poor), but gets more complicated for the 5 bandings I want.

I must be able to define the first variable and then use that within the iif statement?

How do I do this in SSRS 2008?

Thanks in advance.


Better to use Switch which returns the first true condition

=Switch( 
  fields!sales.value/fields!contacts.value < value1, "very poor",
  fields!sales.value/fields!contacts.value < value2, "poor",
  ...
  fields!sales.value/fields!contacts.value < value(n-2), "good",
  fields!sales.value/fields!contacts.value < value(n-1), "very good",
  True, "excellent"
)

where value1 < value2 < ... < valuen.

The final True is dummy like the use of default in an SQL Case expression


An alternative is using custom vb code you can create a function

Public Function GetRating( ByVal rating As Decimal ) As String

Select Case rating

 Case Is < value1
     Return "poor"
...

Case Is < valuen
return "very good"

Case Else
Return "excellent"

End Function

Then in the rows use the expression

= Code.GetRating( fields!sales.value/fields!contacts.value )
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜