简体   繁体   中英

How to check for NULL values when using the SUM function in SSRS

By default, the SUM function in SSRS excludes NULLs. I want to be able to check for ANY NULL values in the details group and throw an error in the summary group. In the details view I use this to check for NULLS:

=IIF(IsNothing(Fields!EquityPrice.Value)) ,"#Error", Fields!EquityPrice.Value*Fields!EquityShares.Value)

This works as desired.

When I use this in my summary section, it ignores the NULLS and returns the SUM of the non-null values. I want to return "#Error" instead:

=IIF(IsNothing(SUM(Fields!EquityPrice.Value))) ,"#Error", SUM(Fields!EquityPrice.Value*Fields!EquityShares.Value))

I have tried eliminating the SUM in the "IsNothing" expression but to no avail. Any help would be appreciated. Thanks in advance!

So just to confirm, if there is at least one NULL value in a group, #Error should be displayed?

You can use the following for the Summary expression:

=IIf(Sum(IIf(IsNothing(Fields!EquityPrice.Value),1,0)) > 0
  , "#Error"
  , Sum(Fields!EquityPrice.Value * Fields!EquityShares.Value))

This creates a count of NULL values - if that count is greater than zero, return #Error .

I made a simple report to test:

在此处输入图片说明

在此处输入图片说明

This uses your expression at the detail level and mine at the summary. Errors for the group with one NULL value as required:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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