Conditional Sum of Sums
Hey all, First time posting here, fairly new to using SSRS and I've spent ~5hours trying to find a solution/figuring this out on my own... Only Google results I return are Devide by Zero sums. (Which is not what I'm looking for... so these are not very helpful...) What I'm trying to do is take 2 sums and devide them out, Summing only on particular conditions... Here's the expression I currently have written; (I've modded this so many times I can't remember my original segment anymore... =iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value = 1, Sum(Fields!LT7.Value, 1, 0) / Sum(Fields!Denom.Value,1,0), "A1C_BMI") If anyone could help I would greatly appreciate it! Thanks in Advance! -Takesen
April 12th, 2011 5:57pm

For the Sum just passing the field name should be enough. The second and third parameter in Sum function in SSRS refers to the scope and rdl recursive options. Please try =iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value = 1, Sum(Fields!LT7.Value) / Sum(Fields!Denom.Value), "A1C_BMI") To avoid division by zero, try like below. Below sample would return the result as zero when it is divided by zero. =iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value = 1, iif(Sum(Fields!Denom.Value) is nothing or Sum(Fields!Denom.Value)=0,0,Sum(Fields!LT7.Value) /Sum(Fields!Denom.Value)), "A1C_BMI") Please try. Hope this helps. Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2011 1:55am

Hey Bilal, Thanks for the reply, not quite solved yet though... using either of the two expressions you provided returns "A1C_BMI" in the field rather than the percentage output. Any ideas?
April 14th, 2011 11:32am

This is indicating that the condition within the IIF (Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value = 1) is always getting evaluated to false. Therefore please check thoroughly that the values num_visits and diab_ed_visits are having values >1 and =1 respectively. If these fields does not match these values, you would always end up getting value A1C_BMI. Can you please provide the structure of your rdl and structure of your dataset. Since you are using SUM within the expression it is important to know the groupings you are having in the table and where you have placed the expression. Please check and provide your feedback. Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
Free Windows Admin Tool Kit Click here and download it now
April 15th, 2011 2:10am

I know it's valid, because I have cells set up to calculate this already. Alone each one works fine. Currently, no groupings. Everything's being calculated via footers, to eliminate duplicate rows of the same results returning, this is purely summary data. (In the future possibly adding a grouping to drill down further but for now none). Expressions that ARE working: Denom; =SUM(iif(Fields!num_visits.Value > 1 And Fields!diab_ed_visits.Value = 1, Fields!Denom.Value, 0), "A1C_BMI") LT7: =SUM(iif(Fields!num_visits.Value > 1 And Fields!diab_ed_visits.Value = 1, Fields!LT7.Value, 0), "A1C_BMI") BTWN7_9: =SUM(iif(Fields!num_visits.Value > 1 And Fields!diab_ed_visits.Value = 1, Fields!BTWN7_9.Value, 0), "A1C_BMI") GT9: =SUM(iif(Fields!num_visits.Value > 1 And Fields!diab_ed_visits.Value = 1, Fields!GT9.Value, 0), "A1C_BMI") Missing: =SUM(iif(Fields!num_visits.Value > 1 And Fields!diab_ed_visits.Value = 1, Fields!labmissing.Value, 0), "A1C_BMI") All of these return values correctly. With that being true, I can't see how Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value = 1, would be returning False.
April 15th, 2011 11:19am

Thank you for the reply. I guess your working expression gives the hint how your structure is. Please try the below expression. =iif(Sum(iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value=1,Fields!Denom.Value,0),"A1C_BMI")=0 or Sum(iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value=1,Fields!Denom.Value,0),"A1C_BMI") is nothing , 0, Sum(iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value=1,Fields!LT7.Value,0), "A1C_BMI")/ Sum(iif(Fields!num_visits.Value > 1 and Fields!diab_ed_visits.Value=1,Fields!Denom.Value,0), "A1C_BMI")) Hope this helps. Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
Free Windows Admin Tool Kit Click here and download it now
April 15th, 2011 1:03pm

You sir... are my hero... I could have sworn I tried an expression like this (just without the divide by zero guard in there...) and it returned errors... I'll have to find the original expression and see what I did wrong... Thank you very very much! works perfect. :)
April 15th, 2011 1:26pm

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

Other recent topics Other recent topics