Dividing two sum fields

  • In my report I have created a summary of one of the values (Total_Progs) so that it will not count anything that contains ABC in the Factory field.

    =Sum(IIf(Fields!Factory.Value <> "ABC", Fields!Total_Progs.Value,0))

    I also have another field called Anotherfield that contains a summary where the Factory value does not contain ABC

    Sum(IIf(Fields!Factory.Value <> "ABC", Fields!Anotherfield.Value,0))

    I want to be able to divide the two columns to show a percentage, can anyone tell me how this would be done in SSRS.

  • Might be as simple as

    =Sum(IIf(Fields!Factory.Value <> "ABC", Fields!Total_Progs.Value,0))/Sum(IIf(Fields!Factory.Value <> "ABC", Fields!Anotherfield.Value,0))

    If you need the total size of Total_Progs/(Total_Progs + Factory), you would have to alter it a little.

    Note, you will have to check the denominator for zero or you'll get a division error.

    If this doesn't work for you, could you provide a few more details... like the structure of the dataset you're using in your report? (Just basic structure and maybe some sample data... as a union query... and an expected output.

  • When I enter the following code into the syntax, the red line is displayed under the code

    =Sum(IIf(Fields!Factory.Value [highlight=#ffff11]<[/highlight]> "ABC", Fields!Total_Progs.Value,0))/Sum(IIf(Fields!Factory.Value <> "ABC", Fields!Anotherfield.Value,0))

    When I run the report I receive the warning,

    An error occurred during local report processing

    The value expression for the textrun 'Texbox...] contains an error BC30451 'It' iis not declared. It may be inaccessible due to protection level.

  • oh, that's <> (not equal), the formatting stuff here screwed it up.

  • Excellent, it worked but is displaying an incorrect value.

  • Not enough information. What do you mean by "incorrect"? Is this a matrix or a table? What did you expect vs what you got?

    got sample data?

  • It does work, apologies, I was adding the wrong values!!! They were very similar fields!!! Spent an hour looking at it and it was something so simple arrgggh!!

  • Ouch! I hate it when I do that... reminds me of the Far Side cartoon... "Thag, take napkin, have mammoth on face."

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply