简体   繁体   English

SSRS如何将If和format语句一起用于负值

[英]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.

相关问题 如何在同一“ If”语句中一起使用“ And”和“ Or”关键字 - How to use “And” and “Or” keywords together in a same “If” statement 如何基于R中的if条件语句重新编码一组变量中的负值? - How to recode negative values in a set of variables based on if conditional statement in R? JQuery if带有负值和正值的语句 - JQuery if statement with negative & positive values 在 Excel 中将正值转换为负值的 IF 语句 - IF statement to turn positive values into negative values in Excel 如何一起使用 lapply 和 ifelse 但在 R 中的 df 中保留原始值 - How to use lapply and ifelse together but keep original values in the df in R 如何使用if-else语句中陈述的值? - How to use values stated in the if-else statement? Android:如何对包/意图值使用if语句? - Android: How to use if statement for bundle/intent values? 如何在SAS中将if语句用于格式为xx的变量值 - How to use an if statement in SAS for a variable value of format x.x 使用 IF 语句分离从文本文件中读取的负值和正值 - Using IF statement for separating negative and positive values read from text file 如何将 mutate 和 IF 语句结合在一起? - How can I combine mutate and an IF statement together?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM