Reporting services 国际投资基金会赢得';t对数字和字符串进行求值

Reporting services 国际投资基金会赢得';t对数字和字符串进行求值,reporting-services,Reporting Services,给定一组输入样本: .5 1 1.333333 Over N/A 0 我曾尝试使用以下表达式有条件地格式化背景色: =IIF(ReportItems!Onhand_PCT.Value < 1 , "Yellow", IIF(ReportItems!Onhand_PCT.Value = "Over" , "Red", "Blue")) =IIF(报告项!现有值=1将是透明的,您可以自定义它 通过更改自定义函数中的“透明” Public Function GetColor(ByVal

给定一组输入样本:

.5
1
1.333333
Over
N/A
0
我曾尝试使用以下表达式有条件地格式化背景色:

=IIF(ReportItems!Onhand_PCT.Value < 1 , "Yellow",
 IIF(ReportItems!Onhand_PCT.Value = "Over" , "Red",
 "Blue"))
=IIF(报告项!现有值<1,“黄色”,
IIF(ReportItems!Onhand_PCT.Value=“Over”,“Red”,
“蓝色”))
然而,无论我如何尝试解决这个问题,它都只适用于字符串或数字,有时两者都不起作用,但永远不会两者都起作用。奇怪的是,我可以(通过使用
ReportItems!Onhand_PCT.Value
上的转换函数使其显式成为一个字符串或数字)使其对某些行起作用,而将其他行保留为白色背景(在我的
IIF
中,“白色”是什么?)

试试看:

=IIF(
   IsNumeric(ReportItems!Onhand_PCT.Value),
   IIF(ReportItems!Onhand_PCT.Value < 1,"Yellow",Nothing),
   IIF(ReportItems!Onhand_PCT.Value = "Over" , "Red","Blue")
 )
现在,在background color属性中,您可以调用这个自定义函数,将
Onhand\u PCT
值作为参数传递给该函数

Public Function GetColor(ByVal value as String) As String
  Dim color As String
  Dim numberValue As Double
  if IsNumeric(value) Then
     numberValue = Cdbl(Val(value))
     color = iif(numberValue < 1, "Yellow", "Transparent")
  else
     color = iif(value = "Over","Red","Blue")
  End if
  return color
End Function
=Code.GetColor(ReportItems!Onhand_PCT.Value)

注意,
Onhand\u PCT>=1
将是透明的,您可以自定义它 通过更改自定义函数中的“透明”

Public Function GetColor(ByVal value as String) As String
  Dim color As String
  Dim numberValue As Double
  if IsNumeric(value) Then
     numberValue = Cdbl(Val(value))
     color = iif(numberValue < 1, "Yellow", "Transparent")
  else
     color = iif(value = "Over","Red","Blue")
  End if
  return color
End Function
=Code.GetColor(ReportItems!Onhand_PCT.Value)

让我知道这是否有帮助。

如果改用switch语句怎么办?@Kidiskidvogingogin开关不起作用。所有显示为白色。@tenmiles,如果值大于或等于1,应该显示什么颜色?另外,当前的PCT报告项是tablix中的一个单元格,它设置为什么表达式?我认为如果
IsNumeric
的计算结果为true,则必须在
IIF
比较中将
value
转换为数字类型。0.5在图片中仍有白色背景。不过我喜欢这个解决方案。@Kidiskidvogingogin,你说得对。似乎IIF比较隐式地将字符串数转换为整数,并将其小数作为整部分。i、 e 0.5转换为5。为了避免这种情况,我在自定义函数中添加了几行。