Divide By Zero On GridCaclulatedColumn

10 posts, 1 answers
  1. Shonda
    Shonda avatar
    36 posts
    Member since:
    Apr 2009

    Posted 29 Jun 2009 Link to this post

    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> 



  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3748 posts

    Posted 02 Jul 2009 Link to this post

    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.
  3. Shonda
    Shonda avatar
    36 posts
    Member since:
    Apr 2009

    Posted 02 Jul 2009 Link to this post

    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?). 
  4. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3748 posts

    Posted 06 Jul 2009 Link to this post

    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.
  5. Shonda
    Shonda avatar
    36 posts
    Member since:
    Apr 2009

    Posted 06 Jul 2009 Link to this post

    Thank you.  Works as expected now.
  6. Peter
    Peter avatar
    98 posts
    Member since:
    Mar 2012

    Posted 26 Apr 2015 in reply to Shonda Link to this post

    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. 

  7. Arsalan
    Arsalan avatar
    2 posts
    Member since:
    Aug 2015

    Posted 18 Aug 2015 Link to this post

    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
  8. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 21 Aug 2015 Link to this post

    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
  9. Arsalan
    Arsalan avatar
    2 posts
    Member since:
    Aug 2015

    Posted 21 Aug 2015 in reply to Kostadin Link to this post

    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 

  10. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 21 Aug 2015 Link to this post

    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
Back to Top