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

Divide By Zero On GridCaclulatedColumn

9 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shonda
Top achievements
Rank 1
Shonda asked on 29 Jun 2009, 04:54 PM
When using iif to handle dividing by zero in my calculated column I am always getting 0.

 <telerik:GridCalculatedColumn DataFields="Pagecount, Teampagecount" Expression="iif({1}=0,0,{0}/{1}*100)" HeaderText="Team Work Ratio" UniqueName="Teamratio" DataType="System.Decimal" ItemStyle-HorizontalAlign="Right" /> 

when I uses the expression iif({1},0,{0}) the column displays the value in the bound column Pagecount and if I use the expression iif({1},0,{1}) the column displays the value in the bound column Teampagecount, but when I put the 2 together I always get 0.

What could be the problem? 

Here is the entire grid

<telerik:RadGrid ID="rgWorkload" runat="server" Skin="Sunset" Width="998px" Height="500px" 
AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" GridLines="None" 
PageSize="50" AutoGenerateColumns="False" ShowFooter="true"
<MasterTableView AllowMultiColumnSorting="true"
<FooterStyle Height="20px" /> 
<Columns> 
<telerik:GridBoundColumn DataField="User" HeaderText="Underwriter" UniqueName="User" 
DataType="System.String" Aggregate="Count" /> 
<telerik:GridBoundColumn DataField="Teamname" HeaderText="Primary Team" UniqueName="Teamname" 
DataType="System.Int32" /> 
<telerik:GridBoundColumn DataField="Mas" HeaderText="MAS" UniqueName="Mas" DataType="System.String" /> 
<telerik:GridBoundColumn DataField="Casecount" HeaderText="Pending Cases" UniqueName="Casecount" 
DataType="System.Int32" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" /> 
<telerik:GridBoundColumn DataField="Doccount" HeaderText="Pending Documents" UniqueName="Doccount" DataType="System.Int32" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" /> 
<telerik:GridBoundColumn DataField="Pagecount" HeaderText="Pending Pages" UniqueName="Pagecount" 
DataType="System.Int32" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" /> 
<telerik:GridBoundColumn DataField="Dupcount" HeaderText="Cases with Possible Dups" 
UniqueName="Dupcount" DataType="System.Int32" ItemStyle-HorizontalAlign="Right" 
Aggregate="Sum" /> 
<telerik:GridCalculatedColumn DataFields="Pagecount, Teampagecount" Expression="iif({1}=0,0,{0}/{1}*100)" 
HeaderText="Team Work Ratio" UniqueName="Teamratio" DataType="System.Decimal" 
ItemStyle-HorizontalAlign="Right" Aggregate="Avg" FooterAggregateFormatString="Mean: {0:0.00}" /> 
<telerik:GridCalculatedColumn DataFields="Pagecount, Overallpagecount" Expression="iif({1}=0,0,{0}/{1}*100)" 
HeaderText="Overall Work Ratio" UniqueName="Overallratio" DataType="System.Decimal" 
ItemStyle-HorizontalAlign="Right" Aggregate="Avg" FooterAggregateFormatString="Mean: {0:0.00}" /> 
<telerik:GridBoundColumn DataField="Compcasecount" HeaderText="Completed Cases(24hrs)" 
UniqueName="Compcasecount" DataType="System.Int32" ItemStyle-HorizontalAlign="Right" 
Aggregate="Sum" /> 
<telerik:GridBoundColumn DataField="Teampagecount" HeaderText="Team Pages" UniqueName="Teampagecount" 
DataType="System.Int32" ItemStyle-HorizontalAlign="Right" /> 
<telerik:GridBoundColumn DataField="Overallpagecount" HeaderText="Overall Pages" UniqueName="Overallpagecount" 
DataType="System.Int32" ItemStyle-HorizontalAlign="Right" /> 
</Columns> 
</MasterTableView> 
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" /> 
<Resizing AllowColumnResize="true" EnableRealTimeResize="true" ClipCellContentOnResize="false" /> 
</ClientSettings> 
</telerik:RadGrid> 



9 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 Jul 2009, 11:54 AM
Hello Shonda,

Unfortunately I could not reproduce the described problem. Please find the attached test project and examine it. Let me know if I am missing something.

Kind regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Shonda
Top achievements
Rank 1
answered on 02 Jul 2009, 01:22 PM
The only difference that I can see is that I am binding to an IList and the 2 fields that I am using in my calculations are defined as type (long?). 
0
Accepted
Georgi Krustev
Telerik team
answered on 06 Jul 2009, 02:50 PM
Hello Shonda,

To avoid this behavior you need to set EnableLinqExpressions to "false". I have attached my test project which I used to implement the required functionality.

Best wishes,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Shonda
Top achievements
Rank 1
answered on 06 Jul 2009, 03:59 PM
Thank you.  Works as expected now.
0
Peter
Top achievements
Rank 1
answered on 27 Apr 2015, 04:51 AM

Ahhh that's tricky! Here's the expression in case you don't want to download the sample: 

Expression='iif({1}=0,0,{0}/{1}*100)'

 

Unfortunately I can't get the sorting / filtering to work... I  guess I have to keep digging. 

0
Arsalan
Top achievements
Rank 1
answered on 18 Aug 2015, 09:44 AM
an expression did not work when "iif({1}=0,0,{0}/{1})" otherwise  when remove division part "iif({1}=0,0,2)" then print "2" on that cell
0
Kostadin
Telerik team
answered on 21 Aug 2015, 06:48 AM
Hi Arsalan,

Could you please confirm that you are using the latest version of UI for ASP.NET? I test the attached sample and on my side the expression works correctly. I would appreciate if you elaborate more on your scenario and the result that you are receiving?

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arsalan
Top achievements
Rank 1
answered on 21 Aug 2015, 10:56 AM

Hi Kostadin,

I use Telerik Winform Controls (version of the year 2012), but now adding custom class Data exception "Invalid Exception  the expression contains undefined function call "thrown  when GridView Datasource Load 

0
Kostadin
Telerik team
answered on 21 Aug 2015, 01:56 PM
Hello Arsalan,

In this case I would ask you to open a new forum thread or support ticket for Telerik Winform Controls. This way the appropriate support officer will handle your case.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Shonda
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Shonda
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Arsalan
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or