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

Expression to count with Condition

3 Answers 584 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shuwie
Top achievements
Rank 1
Shuwie asked on 18 Nov 2010, 09:01 AM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Paul Coakley
Top achievements
Rank 2
answered on 22 Nov 2010, 11:36 AM
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
0
Shuwie
Top achievements
Rank 1
answered on 23 Nov 2010, 10:16 AM
Hi Paul,

Thanks for your reply.
It works like a charm.
0
sumith
Top achievements
Rank 1
answered on 25 Feb 2016, 04:38 AM

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)

Tags
General Discussions
Asked by
Shuwie
Top achievements
Rank 1
Answers by
Paul Coakley
Top achievements
Rank 2
Shuwie
Top achievements
Rank 1
sumith
Top achievements
Rank 1
Share this question
or