[英]SSRS- how SUM function ignore negative values
i want to add only positive values in a aggregate function, ie sum. 我只想在聚合函数中添加正值,即求和。 it should only add positive value.
它只能增加正值。 what i am doing is
我在做什么
SUM(((Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value)/(Fields!RemaningDays.Value+1)))
SUM((((Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value)/((Fields!RemaningDays.Value + 1))))
but now i want to ignore the negative values to add. 但现在我想忽略要添加的负值。
You need to change the numerator to an IIf
expression that will return 0 if the existing value is negative, ie change 您需要将分子更改为
IIf
表达式,如果现有值为负,则该表达式将返回0,即
Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value
to something like: 像这样:
IIf(Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value > 0
, Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value
, 0)
Depending on the underlying data types, you may need a cast to prevent an aggregation of different data types in the expression and hence #Error
being displayed in the report, ie 根据基础数据类型,您可能需要强制转换以防止表达式中不同数据类型的聚合,从而在报告中显示
#Error
,即
IIf(Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value > 0
, Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value
, CDbl(0))
or 要么
IIf(Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value > 0
, Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value
, CDec(0))
So the whole expression will be like: 因此整个表达式将如下所示:
SUM(((IIf(Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value > 0
, Fields!MonthlyTarget.Value-Fields!MonthToDateUnits.Value-Fields!DUSales.Value
, 0))/(Fields!RemaningDays.Value+1)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.