Carrying out a SUMIF like operation using SQL Server Report Builder
Solution 1
The data type of the column 'kWp' is Decimal so you need to either convert the default value to 0.00 or cast the column to double
SUM(iif(Fields!ProjectTypeID.Value = 2,cdbl(Fields!kWp.Value),0.00))
Solution 2
I had similar problem, this worked for me:
=Sum(iif(Fields!date_break.Value = "0001-01-01",Fields!brkr_fee.Value, nothing))
zb
Solution 3
To get the sum
of the kWp of all projects of type 2, the expression is as follows,
=IIf(Fields!ProjectTypeID.Value=2,sum(Fields!kWp.Value),0)
I hope this will help u.
Daniel Neal
I work as a Clojure/ClojureSciript Developer at Social Superstore, where we are building a place for budding entrepreneurs to curate online stores without the associated risks and overheads of setting up bricks and mortar stores. Previously, at EvoEnergy, I worked in C#, WPF and SQL server to provide internal applications for scheduling, stock control. Outside of work - I'm currently learning to make dresses and am training to be a focusing practitioner.
Updated on July 09, 2022Comments
-
Daniel Neal almost 2 years
I'm trying to produce a conditional sum in SQL Server Report Builder 3.0.
My expression looks like this:
=Sum(Iif(Fields!ProjectTypeID.Value=2,Fields!kWp.Value,0))
I'd hoped that this expression would produce a sum of the kWp of all projects of type 2.
Unfortunately, it is not to be. And I can't seem to work out why. It just returns a 0 result, even though I know that there are non-zero values in the kWp column, and the column does not contain nulls.
A colleague did manage to get a positive result by replacing the
Fields!kWp.Value
with
1 * Fields!kWp.Value
But we have no idea why this works, and therefore, can't really trust the answer.
How can I get this conditional sum to behave itself?
-
Daniel Neal almost 12 yearsThanks for your answer. Are you sure this will only sum the values for which this is true? Written this way round, it looks like the if will be performed first - and then return the sum of all the fields.
-
HEDMON over 4 yearsI tried and the result was the same as =SUM(Fields!kWp.Value)