RDLC Expression shows #Error - rdlc

My writing an Expression RDLC SSRS
((Sum(Fields!MockObtMarks.Value))/(Sum(Fields!MockTotalMarks.Value))) * 100
Now this expression shows #Error when the sum (0/0) *100
i have used if and switch case still not working

You should really show the expressions you tried in your question, but this should do:
=IIF( (Sum(Fields!MockTotalMarks.Value)) = 0, 0, ((Sum(Fields!MockObtMarks.Value))/(Sum(Fields!MockTotalMarks.Value))) * 100 )

Related

isnull(#variable, 1) but for 0 instead of null

I have an equation that multiplies loads of variables together, if one of those variables is 0 then I don't want it included in the equation by substituting it for 1 which won't affect the result.
A case when - then, statement for each variable validating if they're greater than 0is a bit clunky.
Is there a similar function like IsNull where if the variable is 0 then it returns an alternate value?
--edit #Backs answer is right but apparently after sql 2012 iif was taken out, when i try to write the statement there is a syntax error at the '=' sign. Is there a replacement for iif after sql-2012?
IIF(#variable = 0, 1, #variable)

How to Multiply using Expression in RDLC ignore if it has string or null values with visual studio 2013

Hi Im having a problem in multiplying the Fields if it is 1 field is string. For ex. Multiplying the Number*String I got #error answer, it should be automatically to 0 but in null values, I have a function correctly and the answer is 0. How to solve my problem?
Here is my code currently function with null values:
=Sum(IIf(Not IsNOthing(Fields!Unit.Value * Fields!Grade.Value), CDbl(Fields!Unit.Value * Fields!Grade.Value), 0)))
I have tried also:
=Sum(IIf(Fields!Unit.Value>0 And Fields!Grade.Value>0, CDbl(Fields!Unit.Value * Fields!Grade.Value), 0))
but the same I got error in multiplying with Number*String.
I've got my screenshot here:

How to make #Error to Empty in RDLC Report Expressions?

My Report had AmountColumn(Fields!Amount) & Amount%Column. I am calculating Grand Total for both the columns using expressions.
I am getting #Error in GrandTotal of Amount%Column when AmountColumn is Empty.
How to make GrandTotal of Amount%Column as Empty instead of #Error.
My Expression Showing #Error:
=FormatNumber(Sum(CDec(Fields!Amount.Value))/Sum(CDec(Fields!Amount.Value),"Tablix2")*100,4)
Try
=IIF(IsNothing(Fields!Amount.Value),"NA",FormatNumber(Sum(CDec(Fields!Amount.Value))/Sum(CDec(Fields!Amount.Value),"Tablix2")*100,4))

Expression to workout in percentages - SSRS

I need to work out the total in percentages:
Please feel free to ask me for anymore details.
=Sum(Fields!OutSLA.Value, "SLAPriority")/Sum(Fields!InSLA.Value, "SLAPriority")*100 I had this but didn't quite go to plan. Very basic knowledge of this sorry
Sorry to post on this one again.. I'm getting weird percentages. i.e. -200 or -Infinity:
To do this at the report level, you can just use something like:
=1 - (Fields!OutSLA.Value / Fields!InSLA.Value)
I wouldn't multiply by 100 in the expression, I would just set the textbox Format property to the approriate value, e.g. P0.
The above expression assumes a detail row. To apply at the in a header or footer row, you would use something like:
=1 - (Sum(Fields!OutSLA.Value) / Sum(Fields!InSLA.Value))
I tried out the first formula in a basic report:
The results are slightly different from your example, but you can see the underlying figures in the last column and why they are rounded in the P0 column.
Edit after comment
You can prevent Infinity values by using an IIf statements to check for 0 InSLA totals, like:
=1 -(IIf(Sum(Fields!InSLA.Value) <> 0
, Sum(Fields!OutSLA.Value) / Sum(Fields!InSLA.Value)
, 0))
-200% is the correct value for that particular row based on your calculation: 1 - (3/1) = -2 = -200 %. What would you expect it to be?
You can do this with convert or with Cast
Convert:
Select
AssignedTo,
INSLA,
OUTSLA,
CONVERT(VARCHAR(50), CAST(((1-(OUTSLA/INSLA))*100) as int))+ '%' as Percentage
FROM SLATABLE
Cast:
Select
AssignedTo,
INSLA,
OUTSLA,
CAST(CAST((1-(OUTSLA/INSLA))*100 as int) AS VARCHAR(50))+ '%' as Percentage
FROM SLATABLE

ReportViewer Division by zero

I have some formulas in my reports, and to prevent divsion by zero I do like this in the expression field:
=IIF(Fields!F1.Value <> 0, Fields!F2.Value/Fields!F1.Value, 0)
This normally works fine, but when both F1 and F2 are zero, I get "#Error" in the report, and I get this warning: "The Value expression for the textbox ‘textbox196’ contains an error: Attempted to divide by zero."
Why is that?
IIF() is just a function, and like with any function all the arguments are evaluated before the function is called, including Fields!F2.Value/Fields!F1.Value. In other words, it will attempt to divide by zero in spite of the Fields!F1.Value <> 0 condition.
There has to be a prettier way than this, but this should work:
=IIF(Fields!F1.Value <> 0, Fields!F2.Value /
IIF(Fields!F1.Value <> 0, Fields!F1.Value, 42), 0)
However, you can use
if Fields!F1.Value <> 0
then
Fields!F2.Value/Fields!F1.Value
else 0
which should work, since it doesn't evaluate the then clause if the "if" section is false.