question

mlutterman avatar image
mlutterman asked

Switch runtime error in expression Attempt to divide by 0?

Any ideas on how to get this to work would be greatly appreciated... The following expression works when the SampleWgt > 0 however when <= 0 I get the following message: [rsRuntimeErrorInExpression] The Value expression for the textrun ‘VineRate.Paragraphs[0].TextRuns[0]’ contains an error: Attempted to divide by zero. In this case the SampleWgt value = 0 so I am expecting just the first condition to execute. The FMVineCnt = 48 and GrossSampleWgt = 16025 so the result should be .29 =Switch(fields!SampleWgt.Value <= 0, fields!FMVineCnt.Value / fields!GrossSampleWgt.Value) * 100, fields!SampleWgt.Value > 0, fields!FMVineCnt.Value / fields!SampleWgt.Value) * 100) Thanks, Mike
valueswitch
6 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

How many rows are you dealing with? No chance that `fields!GrossSampleWgt.Value` could ever be 0? Is this the actual code? There are three right parentheses ')' but only one for the left. Not sure if that might be it or if it's just a typo or paste issue.
1 Like 1 ·
The Query result set in this case is returning just 1 row and the GrossSampleWgt is always > 0. Actual code is below, had a typo Switch(fields!IdahoSampleWgt.Value <= 0,(fields!FMVineCnt.Value / fields!GrossSampleWgt.Value) * 100, fields!IdahoSampleWgt.Value > 0,(fields!FMVineCnt.Value / fields!IdahoSampleWgt.Value) * 100)
0 Likes 0 ·
Just an observation... If I change the expression to =IIF(fields!IdahoSampleWgt.Value <= 0,(fields!FMVineCnt.Value / fields!GrossSampleWgt.Value) * 100, 999) then no error is returned.
0 Likes 0 ·
using the IIF, will it still work if you replace 999 with your second calculation: `(fields!FMVineCnt.Value / fields!IdahoSampleWgt.Value)`
0 Likes 0 ·
Nope, thats when I get the Attempted to divide by zero msg.
0 Likes 0 ·
Show more comments

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.