Expression
="(({0} - {1}) / {0}) * 100"
Some of the column values that i use in my calculation can under certain circumstances have zero values. This obviously raises a divide by zero exception. I want in these instances to display a percentage of zero.
I dont seem able to intercept or handle the exception and set the cell value to 0 ( i.e perhaps at item databound event or similar).
Any suggestions as to how i can perform this - if not, i presume I will have to make the calculations in the database and bind as normal boundcolumns.
9 Answers, 1 is accepted
There is a trick to check if any of your augments is zero.
For example you can change this expression: ="(({0} - {1}) / {0}) * 100"
into =" iif({0} = 0, 0, (({0} - {1}) / {0}) *100) ) ".
I hope that's helpful.
Regards,
Nikolay
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

Thanks, your trick works perfectly. :)
Thanks,
Mangesh

is there a simple/ automatic way to export the gridCalculateColumn to Excel
any help is appreciated
Thanks
Manish

can you please provide any solution to export the GridCalculateColumn when doing export to excel , without doing the manual calculation in the app code.
my expression is ="(({0}-{1})/{1})*100"
so suppose -( (10-5)/5) * 100) , it should be 100 % , but it shows 1 % , so somehow , its not multiplying by 100 when exported to excel
is there a simple/ automatic way to export the gridCalculateColumn to Excel
any help is appreciated
Thanks
Manish
I was not able to reproduce the issue. I prepared a small sample and attached it to this forum post. Could you please give it a try and let me know how it differs from your real setup?
Kind regards,
Kostadin
the Telerik team

DataFormatString
="{0:###,##0.00}%" or
DataFormatString
="{0:c}%"
do you see any problem in this expression
Expression
="iif({1}=0,0,iif(({0}-{1})=0,0,(({0}-{1})/{1})*100))"
however this expression is giving me a perfect output on Grid display
any idea?

[0}*{1} , [0}+{1},[0}-{1} [0}/{1} , these are working fine.(as these are column cells)
and the sample you provided says the same and it was working for me anyways.
problem arises when you *100
try this in your sample

found the reason for my export to excel is not working good and its not showing value multiplied by 100 in the exported excel
Expression= iif({1}=0,0,iif(({0}-{1})=0,0,(({0}-{1})/{1})*100))"
the above expresion is good , but when when you Dataformating something like this{0:C}% just to show percent in the gris rows
so when you export to excel, the excel sees a percent Sign , and tries to a formatting on top of that . so if you see the formatting for oercent in excel i- it is again divinding it by 100 . so thats the reason , i was not getting multiply by hundred when exporting.
so the culprit was % sign in the grid rows, so i had to delete the % in th grid rows ,which is not what i wanted , but...
hope this help s anyone have same issue.
also let me know if telerik has some workaround for this
Thanks
Manish
Note that this is an Excel behavior and could not be changed. Nevertheless as a workaround you could remove the DataFormatString from the column when exporting to excel and apply mso-nimber-format. For your convenience I prepared a small sample and attached it to this forum post. Please give it a try and let me know about the result.
Regards,
Kostadin
the Telerik team