This is a migrated thread and some comments may be shown as answers.

Divide By Zero On RadCalculatedColumn

9 Answers 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Mawn
Top achievements
Rank 1
Andy Mawn asked on 11 Jun 2008, 10:09 AM
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.

9 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 12 Jun 2008, 04:50 PM
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) ) ".

I hope that's helpful.

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mangesh
Top achievements
Rank 1
answered on 27 Nov 2012, 05:41 PM
Hi  Nikolay Rusev,

Thanks, your trick works perfectly. :)

Thanks,
Mangesh
0
Manish
Top achievements
Rank 1
answered on 13 Mar 2013, 10:25 PM
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
0
Manish
Top achievements
Rank 1
answered on 14 Mar 2013, 06:55 PM
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
0
Kostadin
Telerik team
answered on 18 Mar 2013, 12:10 PM
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,
Kostadin
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.
0
Manish
Top achievements
Rank 1
answered on 20 Mar 2013, 02:05 PM
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?
0
Manish
Top achievements
Rank 1
answered on 21 Mar 2013, 01:32 PM
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

try this in your sample
0
Manish
Top achievements
Rank 1
answered on 22 Mar 2013, 02:08 PM

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

0
Kostadin
Telerik team
answered on 25 Mar 2013, 09:51 AM
Hi 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
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.
Tags
Grid
Asked by
Andy Mawn
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Mangesh
Top achievements
Rank 1
Manish
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or