简体   繁体   English

SSRS表达多个条件

[英]SSRS expression multiple conditions

I'm trying to build a SSRS expression on a tablix. 我正在尝试在tablix上构建SSRS表达式。 Its using two Parameters: Product which has {A,B,C,D} as products and Qtr as quarters 1,2,3,4 and Amounts as 1000,2000,3000,4000,5000,6000,7000. 它使用两个参数:以{A,B,C,D}为乘积的产品和Qtr为1,2,3,4季度和数量为1000,2000,3000,4000,5000,6000,7000的产品。 I'm trying to add an extra condition to Product A by saying if the Product is A and qtr is 4 then the Amt is 2000 if not the Amt is 3000. The following expression is giving me #Error in the tablix. 我试图通过说如果Product是A且qtr是4,则Amt是2000,如果不是Amt是3000,则向Product A添加额外条件。以下表达式在tablix中给我#Error。 I don't know what is wrong. 我不知道怎么了

=iif(Parameters!Product.count=2,1000,iif(Parameters!Product.Value(0)="A" AND Parameters!Qtr.Value(0)=4,2000,iif(Parameters!Product.Value(0)="A",3000,iif(Parameters!Product.Value(0)="B",4000,iif(Parameters!Product.Value(0)="C",5000,iif(Parameters!Product.Value(0)="D",6000,7000)))))) 

This may not be the most elegant solution, but it worked in my test case. 这可能不是最优雅的解决方案,但在我的测试案例中有效。 I'm not exactly sure why, but the references to Parameters!Product.Value(0) are causing the issue. 我不确定为什么,但是对Parameters!Product.Value(0)的引用导致了此问题。 Doesn't make sense to me, since based on your expression checking for count = 2 it must be a multi-value parameter, which means it cannot be null, so there will always be a Value(0). 这对我来说没有意义,因为根据您的表达式检查count = 2,它必须是一个多值参数,这意味着它不能为null,因此始终会有Value(0)。 You can put =Parameters!Product.Value(0) in a text box by itself, but putting it in a conditional causes a problem apparently. 您可以将=Parameters!Product.Value(0)本身放在文本框中,但将其放在条件中显然会引起问题。

First of all, Switch is much better suited to this task than nested IIf, so that is what I used instead. 首先,Switch比嵌套的IIf更适合此任务,因此我改用了它。 That doesn't have anything to do with the error, but it is much more readable and easier to understand. 这与错误没有任何关系,但是它更具可读性和易于理解。

To get around the issue with referencing Parameters!Product.Value(0) within the conditional, I created a comma separated string of the parameter values, and then took just the first character from that string with Left(Join(Parameters!Product.Value, ","), 1) . 为了解决在条件中引用Parameters!Product.Value(0)的问题,我创建了一个用逗号分隔的参数值字符串,然后使用Left(Join(Parameters!Product.Value, ","), 1) If the actual values for Product are a variable amount of characters, you would need to modify that to parse the value before the first comma, but since your values are A, B, C, and D this will work. 如果Product的实际值是可变数量的字符,则需要修改该值以在第一个逗号之前解析该值,但是由于您的值是A,B,C和D,因此可以使用。 So the full expression would look like this: 因此完整的表达式如下所示:

=switch(
    Parameters!Product.Count = 2, 1000,
    Left(Join(Parameters!Product.Value, ","), 1) = "A" and Parameters!Qtr.Value = 4, 2000,
    Left(Join(Parameters!Product.Value, ","), 1) = "A", 3000,
    Left(Join(Parameters!Product.Value, ","), 1) = "B", 4000,
    Left(Join(Parameters!Product.Value, ","), 1) = "C", 5000,
    Left(Join(Parameters!Product.Value, ","), 1) = "D", 6000,
    true, 7000
)

instead of implementing with IIF try with the switch statement. 而不是使用IIF来实现,请尝试使用switch语句。 which make coding simple and manageable in long-term 从长远来看,这使编码变得简单且易于管理

example: =switch ( Fields!filestatus.Value="P","lightGreen" ,isnothing(Fields!filestatus.Value),"IndianRed" ,true,"No Color" ) 例如:= switch(Fields!filestatus.Value =“ P”,“ lightGreen”,isnothing(Fields!filestatus.Value),“ IndianRed”,true,“ No Color”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM