Question

I am having problems trying to do the following. I am trying to incorporate an iif statement inside a caption. This is the current line that is evaluated on the label:

=round(@ Data.rp_TATStatAtBenchmark~ / @ Data.rp_TATStatCount~ * 100) + "%"

and I have changed it to the following to handel the error when @ Data.rp_TATStatCount = 0 and @ Data.rp_TATStatAtBenchmark = 0 as well (for some reason the report shows ??? when the second value is 0 instead of showing just "0%". Anyhow, this is what I'm trying to write:

=IIf((@ Data.rp_TATStatAtBenchmark~ = "0" OR @ Data.rp_TATStatCount~ = "0"),"0%", round(@ Data.rp_TATStatAtBenchmark~ / @ Data.rp_TATStatCount~ * 100) + "%")

but it is not working. Any help would be appreciated. Thank you!

Was it helpful?

Solution

If the @Data.rp_TATStatCount~ value is 0, the reason you're seeing a result of "???" is because divide by zero is a mathematical expression which has no meaning ('undefined'). This would always return as undefined '???' instead of a number -- so the result would never be 0. Since token variables are simply replaced, the expression is still be checked for validity, even if you're using an iif() statement.

If you want to create an exception for divide by zero, then you will also need to provide a calculation to check for when rp_TATStatCount = 0, and either replace it with a non-zero integer, or use a different column name. The best way might be to create a second Calculated Column that checks for zero (your iif() statement) and then use this newly created column to perform your round() function.

here's a quick example inside a Static datalayer using your existing column names:

<DataLayer Type="Static" ID="dlStatic">
 <StaticDataRow rp_TATStatAtBenchmark="0" rp_TATStatCount="0" />
   <CalculatedColumn Formula="iif(@Data.rp_TATStatCount~=0, 1, @Data.rpTATStatCount~)" ID="StatCount2" />
   <CalculatedColumn Formula="iif(@Data.rp_TATStatAtBenchmark~ = &quot;0&quot; OR @Data.rp_TATStatCount~ = &quot;0&quot;, &quot;0%&quot;, round(@Data.rp_TATStatAtBenchmark~ / @Data.StatCount2~ * 100) + &quot;%&quot;)" ID="pctCol" />
</DataLayer>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top