views:

575

answers:

3

Im trying to sum an expression in visual studio and just keep getting an #error but not sure why as this si the first time i have tried to sum an expression, only ever done it on a single field before. Any Suggestions!!!

 =IIf(Fields!STATUS.value = "Completed" AND Fields!DONOTINVOICE.value = True, Fields!ORDERCOST.Value, "")
+1  A: 

The value of the IIf() will evaluate to a string ("") when your condition is false. You can't sum a string. Try using 0 instead.

recursive
Just to be explicit: =IIf(Fields!STATUS.value = "Completed" AND Fields!DONOTINVOICE.value = True, Fields!ORDERCOST.Value, 0)
Michael Haren
A: 

Do you mean like this, just tried that and dosent sum anything just get 0 :(

=Sum(IIf(Fields!STATUS.value = "Completed" AND Fields!DONOTINVOICE.value = 1, Fields!ORDERCOST.Value, 0))

Now your sum appears to consist of a single value. What are you trying to sum? What language is this?
recursive
im writing a report in visual studio, so the expression is in the footer of the table.
There is no SUM function being used anywhere?
Dalin Seivewright
Sorry, I am not too familiar with visual studio reports. I didn't even know there was such a thing. You could try creating an alias for the IIf expression in your data set, then just sum that alias. Other than that, I don't know.
recursive
The sum is after the = sign?! Yeah ive only just started using visual studio myself, why did i have to get a hard report to do so soon!!!!
Yeah I saw it two seconds after I commented :|Does the report preview state anything more about the error?Try doing " =SUM(IIF(true, Fields!ORDERCOST.value, 0))
Dalin Seivewright
What just round the order cost field, as when i do that it only likes having the bracked beofre the commer so sums all the ordercost totals, or do you mean round the whole expression. Tes rest of the rpeort works so i know the epressions are ok as these are used in rows above.
A: 

Ok couldnt figure out the sum on an expression so ive just used a case statement in a new dataset to build the sum feature. Example below, this is in an inner query and i have done a sum in the main bit. Just incase anyone else gets this issue this is how i resolved it.

CASE WHEN TBL_REPAIR_ORDER.STATUS = 'Completed' AND TBL_REPAIR_ORDER.DONOTINVOICE = 1 THEN TBL_REPAIR_ORDER.ORDERCOST ELSE 0 END AS Completed