SSRS formule ou d'expression pour modifier NaN à 0
-
27-10-2019 - |
Question
J'utilise l'expression suivante pour un pourcentage:
=Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name")
Days.Value montre que 0 mais dans certains de mes résultats au lieu de lire 0% dans ma colonne de pourcentage, il est en train de lire NaN (Not a Number).
Quelqu'un sait l'expression exacte forumla i besoin et où je devrais coller dans mon expression actuelle de dire: « Où NaN montre, mettre un « 0 » à la place? »
(Voir l'image)
La solution
How about
=IIF(Fields!Days.Value > 0,Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),0)
Autres conseils
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"))
I used this for similar case,
=REPLACE(Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),"NaN","0")
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"))
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.
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"))
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.