How to use Built-in Functions

11 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. 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


  4. 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 >>
  5. 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

  6. 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.

  7. 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
  8. 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.

  9. 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.

  10. Al
    Al avatar
    3 posts
    Member since:
    Aug 2017

    Posted 28 Aug Link to this post

    I am using the example on WPF documentation and I can't find out how the aggregate functions works. Does "average" of salary field should work this way?
  11. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    587 posts

    Posted 31 Aug Link to this post

    Hello Al,

    As suggested by my colleagues, the Average function is meant to be used with a collection of numeric values. For example, if our Employee class had a Ratings property of type List<int> we could filter the RadGridView in the Getting Started article of the RadExpressionControl in a similar manner.

    Average(Ratings) >= 3

    If you wish to display the average value of the Salary property of the items in RadGridView's ItemsSource, you can define an aggregate function for the Salary column.

    I hope you find this information helpful. Do let me know if you need any further clarifications on the matter.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top