How to use Built-in Functions

9 posts, 0 answers
  1. Brian
    Brian avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Feb 2012 Link to this post

    Hi

    Can you tell me the correct format to call the built-in functions in Expression Editor.
    e.g. Average( 1.5, 2.5, 3.3 ) does not work. What is the correct format?

    Thanks
    Brian

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Feb 2012 Link to this post

    Hello,

    I believe the correct way is as follows:
    Average(MyProperty) where MyProperty is IEnumerable of some numeric type and is a property of the object set as Item of the Expression editor.

    Regards,
    Pavel Pavlov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Brian
    Brian avatar
    4 posts
    Member since:
    Feb 2012

    Posted 22 Feb 2012 Link to this post

    Hi Pavel

    No, this does not work, even if I use your example from your demo.
    (e.g. Average ( UnitPrice )  - UnitPrice is a numeric type)
    See the attachment.
    Please tell me what is wrong.

    Thanks
    Brian


  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 23 Feb 2012 Link to this post

    Hi Brian,

    IEnumerable<Numeric type>  e.g.  List<Decimal>  is what I meant.

    To perform aggregation you need a collection as input , not a single value.

    All the best,
    Pavel Pavlov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Brian
    Brian avatar
    4 posts
    Member since:
    Feb 2012

    Posted 24 Oct 2012 Link to this post

    Just getting back to this topic. I've implemented my data as a List object which is an IEnumerable type
    e.g. List<double> hours

    Most of the aggregate functions in the Expression Editor now work
    e.g. Count(hours) also First, Last, Max, Min etc.

    However I can't get Average() or Sum() to work
    e.g. Average(hours) is not accepted

    In the help the only difference I can see is that Average is defined as Average([List (Of Number)]) whereas Count is simply Count([List])

    Thanks
    Brian

  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Oct 2012 Link to this post

    Hello,

     You can check this article for more info about aggregates methods:
    http://msdn.microsoft.com/en-us/library/bb548651.aspx

    Kind regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Paul
    Paul avatar
    4 posts
    Member since:
    Mar 2013

    Posted 28 Mar 2013 Link to this post

    Hello, 

    Did the issue with Sum() & Average() ever get resolved? 

    I'm seeing the same behavior...Count, Max, Min, First, Last work but not Sum & Average.

    Would be interested in knowing if you found a resolution.

    Paul
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Apr 2013 Link to this post

    Hello Paul,

    The expression editor uses the standard .NET Framework extension methods of the Enumerable class which you can find here. We simply parse the string that the user has entered and then create a lambda expression that calls one of those standard .NET methods of the Enumerable class.


    So let's take the Average method for example. Here is its signature:
    public static float Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)

    If you were writing C# code yourself you could write something like this:
    var result = customers.Average(customer => customer.Age);

    The same applies for the Sum method.
     

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Apr 2013 Link to this post

    Hello,

    I would like to correct my previous response. I have tested how the Average and Sum functions work and as it turns out - the suggested syntax will not work. You should pass IQueryable instead of IEnumerable.

    If you have IEnumerable<TSource> collection (not IQueryable), then you could invoke the Average (Sum) function on it similar to:
    Average(collection.AsQueryable()) (Sum(collection.AsQueryable())).
     
    I hope this helps.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner