SSRS 2005: Sum based on values in 2 other columns.
Hello all, I have a problem similar to this post (http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/583b73c7-60ab-4662-be95-7dd2b28af7fb) but I needed to check the value of 2 columns before the sum function. I worked out the AND part and there are no errors when previewing the report. I get an error in the report field (#Error), though, only when there are matching criteria within the month. If there is no matching criteria, the field reports 0, which is correct. This is in a table group footer where the table is grouped by month and year. The expression is below. Can anyone point me in the right direction to resolve the issue? ="Routine Stents " & sum(iif((Fields!Processing.Value="Light Mic.") AND (Fields!Specimens.Value="Stent"),Fields!NumSpecimens.Value,0)) Thanks, Jeff Updated: my apologies. i do get the following error. Warning 14 [rsAggregateOfMixedDataTypes] The Value expression for the textbox ‘textbox42’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type. c:\report server projects\estimatedmonthlyplan\estimated monthly plan\estimated monthly plan\Estimated Monthly Plan.rdl 0 0
February 16th, 2011 7:42am

Hi Jeff, Based on error message, the problem is caused by aggregating on data of varying data types. So, what’s the data type of the data field NumSpecimens? Genearlly, as the similar thread you posted, we need to convert values which need to be aggregated to the same data type. For example, we can convert them to Double by changing the expression to ="Routine Stents " & sum(iif((Fields!Processing.Value="Light Mic.") AND (Fields!Specimens.Value="Stent"),CDbl(Fields!NumSpecimens.Value),CDbl(0))) Thanks, Tony ChainTony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
February 16th, 2011 9:58pm

Thank you, Tony. That worked. I do wonder why I need to convert. The datatype for NumSpecimens is Integer in the Access table. In this case, 0 is not considered an integer or the field type is not maintained when connecting SSRS to an Access table via ODBC? Or, is there another reason both numbers need to be converted? Again, thank you for your assistance. Jeff
February 17th, 2011 7:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics