Expression to count with Condition

4 posts, 1 answers
  1. Shuwie
    Shuwie avatar
    2 posts
    Member since:
    Nov 2010

    Posted 18 Nov 2010 Link to this post

    I have a column with different types of Category A, B and C.
    eg. How do I write an expression to count the number of Category A?

    I tried [=Count(Fields.Status='A')] and [=Count(Fields.Status) where Fields.Status='A']

    Please help.
  2. Answer
    Paul Coakley
    Paul Coakley avatar
    6 posts
    Member since:
    Dec 2008

    Posted 22 Nov 2010 Link to this post

    Hey Shuwie. I did this with a user function

    using the knowledge that the aggregate functions likwe Count work on non-null values, I defined a static function like so in the code behind (edited for brevity):

    namespace My
      using System;
      public static class Functions
        public static object Match(object data, object match)
          string sData = Convert.ToString(data);
          string sMatch = Convert.ToString(match);
          return String.Equals(sData, sMatch) ? data : null;

    and then (I did this in a Binding, but you should be able to do this anywhere) used the Expression

    =Count(My.Functions.Match(Fields.[Some Field], "test value"))

    which yields the equivalent of a count where [Some Field] equals "test value", so you could do this like:

    =Count(My.Functions.Match(Fields.Status, "A"))

    The same approach could be used for more sophisticated conditions I expect - though my guess is that lambda functions are out in telerik reporting's expression syntax.

    Hope that helps

    Leon Jollans
  3. DevCraft R3 2016 release webinar banner
  4. Shuwie
    Shuwie avatar
    2 posts
    Member since:
    Nov 2010

    Posted 23 Nov 2010 Link to this post

    Hi Paul,

    Thanks for your reply.
    It works like a charm.
  5. sumith
    sumith avatar
    1 posts
    Member since:
    Feb 2016

    Posted 24 Feb Link to this post

    I have a group row all the columns grouping with same value, but only 1 column should be group with different value how to resolve this in telerik designer reporting .

    Ex: col1(group A), col2(group A),col3(group A),col4(group A),col5((group B),col6(group A)

Back to Top