16

I am using the following expression to work out a percentage:

=Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name")

Days.Value is showing as 0 however in a few of my results instead of reading 0% in my percentage column it is actually reading NaN (Not a Number).

Does anyone know the exact expression forumla i need and where I should paste it in my current expression to say "Where NaN is showing, put a '0' instead?"

(See image)enter image description here

DatumPoint
  • 419
  • 4
  • 21
JsonStatham
  • 9,770
  • 27
  • 100
  • 181

7 Answers7

22

I didn't have luck with the above answers. Here's what worked for me:

=IIF(Single.IsNAN(Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name")), 0, Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"))
hurleystylee
  • 602
  • 1
  • 10
  • 18
16

How about

=IIF(Fields!Days.Value > 0,Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),0)
Pedram
  • 6,256
  • 10
  • 65
  • 87
general exception
  • 4,202
  • 9
  • 54
  • 82
  • 1
    I tried something similar to this: =IIF(Sum(Fields!TotalPrice.Value)/Sum(Fields!Orders.Value) = 0, 0, Sum(Fields!TotalPrice.Value)/Sum(Fields!Orders.Value) netted me some weird results in a text box I deemed as currency. The answer above worked perfectly. Thanks! – John Waclawski Jun 13 '14 at 13:06
  • This solution still gave me the same error. I've answered this question with what worked for me. – hurleystylee Jul 06 '16 at 14:12
10

I used this for similar case,

=REPLACE(Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),"NaN","0")

5

Here's another option. It should solve the problem, and also get rid of Infinite responses:

=val(replace(Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),"NaN","0"))
Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24
Ratsnake
  • 51
  • 1
  • 1
3

This is the simplest & best, I think,

=Switch(
Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") = "NaN",Nothing,
Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") = "Infinity",Nothing,
Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") = "-Infinity",Nothing
)

You can also put a 0 instead of nothing.

Aditya
  • 2,299
  • 5
  • 32
  • 54
3

Try

=IIf(Fields!Days.Value Is Nothing Or Sum(Fields!Days.Value, "Date_month_name") Is Nothing, 0, Fields!Days.Value / Sum(Fields!Days.Value, "Date_month_name"))
Pedram
  • 6,256
  • 10
  • 65
  • 87
Cody Konior
  • 727
  • 1
  • 7
  • 19
0

I had a similar issue to this and found that the following was easiest to do.

=Iif(
Fields!Days.Value.Value <> 0 AND Sum(Fields!Days.Value, "Date_month_name") <> 0
, Fields!Days.Value.Value/Sum(Fields!Days.Value, "Date_month_name")
, 0
)

Probably not the best solution, but works.

Arnine
  • 123
  • 6