SUM Function Expression

  • Please help: Below is how my output currently looks. In the Cost Element Total group in July it shows a sum total of 18,950 when it should show 3,950 as the total of the 3 detail rows. Dec should show 5,000 as the group total and not zero. June should show10,000 as the group total and not zero. Instead, July's group total is 18,950, which is the total of all months. Below is the expression I have used for the Cost Element Total Group:

    =iif(Fields!PERIODID.Value=1 and Fields!Year1.Value = Parameters!Year.Value,sum(Fields!Cost_Code_Actual_Cost.Value),"0")

    Jul Dec June

    Cost Element Total Group 18,950 0 0

    Detail Row 1 3,950 0 0

    Detail Row 2 0 5,000 0

    Detail Row 3 0 0 10,000

    PERIODID.Value = 1 refers to July. Only 3 months have been included in this example as the other months are all zero months.

    Thanks in adavance for any help.

  • Hi Paula,

    Do you use some kind of grouping to keep the Months together (e.g. Matrix) ? or are the values for the months in different columns in the Dataset?

    What is the value in @YearValue? If it doesn't Identify the month as well I would guess that the statement you provided does as it should 🙂

    This is just a shot in the blue. Please give some more Information.

  • Hi, you could try CASE WHEN statement instead IFF and compare the execution time.

    http://technet.microsoft.com/en-us/library/ms181765.aspx

  • Hi Thanks for the feedback. Reporting services doesn't support the CASE statement from my understanding. Is that your understanding?

  • Within Reporting Services you can use Switch instead of Case. Functionality is pretty much the same.

  • OK. Thanks!! Could you show me how to convert my code to use the switch function?

    The code expression is below:

    =iif((Fields!PERIODID.Value=1) and (Fields!Year1.Value = Parameters!Year.Value),(sum(Fields!Cost_Code_Actual_Cost.Value,"Cost_Element_Group")),"0")

  • Hi, here you have doc:

    http://msdn.microsoft.com/en-us/library/ms157328.aspx

  • Hi, you can try RAQ Report. I'm using RAQ Report now. I find it very useful. It's a free java reporting tool. Besides, RAQ Report provides free reliable Doc, Demo, Forum, Email support. If you have report problem, you can turn to RAQ Report'Get Technical Support for help. RAQ Report has many functions as shown below:

    You can download this free reporting tool at http://www.raqsoft.com.

    Welcome to my blog[/url].:P

  • Thanks for all the feedback

  • paula (8/4/2009)


    =iif((Fields!PERIODID.Value=1) and (Fields!Year1.Value = Parameters!Year.Value),(sum(Fields!Cost_Code_Actual_Cost.Value,"Cost_Element_Group")),"0")

    If I read your expression correctly, you have just one decision to make with two criteria. For that, the IIF-Function is just fine. But like I said before, you can't address a single field in an Aggregate-row.

    Either you would need to make a calculated filed that you can sum afterwards. Or you move that calculation to the SQL-Statement.

    Try this:

    add this statement as Calculated Field to your Dataset:

    =iif((Fields!PERIODID.Value=1) and (Fields!Year1.Value = Parameters!Year.Value),(Fields!Cost_Code_Actual_Cost.Value,"Cost_Element_Group")),cint("0"))

    then add this to your Group-Footer

    =sum(yourCalculatedField)

    Just a shot in the blue, I couldn't test this.

  • That works just fine!! Thanks very much for your help!!

  • If the iif test is true, you're returning the sum over ALL rows. What I think you meant to do was to sum only those records which pass the iif test. In other words, instead of

    iif(,sum(field),0)

    ...you might try...

    sum(iif(,field,0))

    Robb

  • OK Thanks

Viewing 13 posts - 1 through 12 (of 12 total)

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