[英]SSRS how to use If and format statement together for negative values
I am trying to display seconds as minutes. 我试图将秒显示为分钟。 Sometimes the value I get is negative. 有时我得到的价值是负的。 This causes problems. 这会引起问题。 I wanted to check if the value is negative so that I can assign a default value. 我想检查该值是否为负,以便可以指定一个默认值。 But I can not get If and Format statement work together. 但是我无法让If和Format语句一起工作。
This is what I have done to display the values without converting into minutes: 这是我所做的显示值而不转换为分钟的操作:
=Fields!RateLossSeconds.Value
This is what I have done to convert the seconds into minutes: 这是我将秒转换为分钟的方法:
=Format(DateAdd("s", Fields!RateLossSeconds.Value, "00:00"), "mm:ss")
This is the code I used to add a condition: 这是我用来添加条件的代码:
=IIF(Fields!RateLossSeconds.Value < 0, 0, Format(DateAdd("s", Fields!RateLossSeconds.Value, "00:00"), "mm:ss"))
As you can see the if statement does not work as desired. 如您所见,if语句无法按预期运行。
The #Error is caused due to SSRS evaluate the whole IIF()
expression before the IIF
logic flow, so even if you are handling the negative values it checks both branches for errors. #Error是由于SSRS在IIF
逻辑流程之前评估整个IIF()
表达式引起的,因此,即使您正在处理负值,它也会检查两个分支是否有错误。
Try using this expression: 尝试使用以下表达式:
=IIF(
Fields!RateLossSeconds.Value < 0, 0,
Format(
DateAdd("s",IIF(Fields!RateLossSeconds.Value<0,0,Fields!RateLossSeconds.Value),"00:00"),
"mm:ss"
)
)
It checks if there is a negative value in the False branch of the first IIF(). 它检查第一个IIF()的False分支中是否存在负值。 In this case I replace the negative values by zero but you can use any value you want to. 在这种情况下,我将负值替换为零,但您可以使用任何想要的值。
Let me know if this helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.