# Divide By Zero On RadCalculatedColumn

1. ##### Andy Mawn
1 posts
Member since:
May 2008

Posted 11 Jun 2008 Link to this post

I have a grid that uses a couple of calculated columns to show percentage calculations.

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.

2. ##### Nikolay Rusev
2287 posts

Posted 12 Jun 2008 Link to this post

Hi Andy Mawn,

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) ) ".

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
3. ##### Mangesh
16 posts
Member since:
Sep 2011

Posted 27 Nov 2012 Link to this post

Hi  Nikolay Rusev,

Thanks, your trick works perfectly. :)

Thanks,
Mangesh
4. ##### Manish
10 posts
Member since:
Oct 2012

Posted 13 Mar 2013 Link to this post

can you please provide any solution to export the GridCalculateColumn when doing export to excel , without doing the manual calculation in the app code.

is there  a simple/ automatic way to export the gridCalculateColumn to Excel

any help is appreciated

Thanks
Manish
5. ##### Manish
10 posts
Member since:
Oct 2012

Posted 14 Mar 2013 Link to this post

little more specific

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
1733 posts

Posted 18 Mar 2013 Link to this post

Hi 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,
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
7. ##### Manish
10 posts
Member since:
Oct 2012

Posted 20 Mar 2013 Link to this post

everything is same for me  , but export to excel is not showing the percent column properly , its not doing part of the calculation when exporting to excel. also found that EqualTo filter is also not working for GridCalculated column with

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?
8. ##### Manish
10 posts
Member since:
Oct 2012

Posted 21 Mar 2013 Link to this post

see the actual problem is when you multiply by 100 or any number

[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

9. ##### Manish
10 posts
Member since:
Oct 2012

Posted 22 Mar 2013 Link to this post

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