Monday, March 7, 2011

Sum IIF Expression

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, "")
From stackoverflow
  • 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.

    Michael Haren : Just to be explicit: =IIf(Fields!STATUS.value = "Completed" AND Fields!DONOTINVOICE.value = True, Fields!ORDERCOST.Value, 0)
  • 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))

    recursive : Now your sum appears to consist of a single value. What are you trying to sum? What language is this?
    Dalin Seivewright : There is no SUM function being used anywhere?
    recursive : 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.
    Dalin Seivewright : 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))
  • 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

0 comments:

Post a Comment