SSRS中的嵌套iif问题



嵌套iif编译错误

=IIf(Fields!no_of_employees.Value = max(Fields!no_of_employees.Value,"DataSet1"),"Lime","Gold",
IIf(Fields!no_of_employees.Value = min(Fields!no_of_employees.Value,"DataSet1"),"Red","Gold"
))

我试图实现嵌套的iif。

如果您查看语句,您已经向第一个IIF传递了4个参数

要写一个正常的IIF,你可以这样做

=IIF(
ConditionA=True,
TrueResult,
FalseResult
)

当你写一个嵌套的IIF时,你会这样做

=IIF(
ConditionA=True,
TrueResult,
IIF(
ConditionB=True,
TrueResult,
FalseResult
)
)

修复你的代码,删除"Gold",的第一个实例。

我更喜欢使用SWITCH()而不是嵌套的IIFs,因为我认为它更容易阅读。如果你想使用SWITCH(),那么你可以重写表达式如下:

=SWITCH(
Fields!no_of_employees.Value = max(Fields!no_of_employees.Value,"DataSet1"), "Lime",
Fields!no_of_employees.Value = min(Fields!no_of_employees.Value,"DataSet1"), "Red",
True, "Gold"
)

最终的True就像ELSE一样。你可以在这里阅读更多关于SWITCH()的信息。

https://learn.microsoft.com/en-us/sql/reporting-services/report-design/expression-examples-report-builder-and-ssrs?view=sql-server-ver16 DecisionFunctions

最新更新