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

How to use Built-in Functions

10 Answers 59 Views
ExpressionEditor
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 22 Feb 2012, 02:56 AM
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

10 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 22 Feb 2012, 12:42 PM
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 >>
0
Brian
Top achievements
Rank 1
answered on 22 Feb 2012, 09:13 PM
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


0
Pavel Pavlov
Telerik team
answered on 23 Feb 2012, 02:32 PM
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 >>
0
Brian
Top achievements
Rank 1
answered on 24 Oct 2012, 09:49 PM
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

0
Vlad
Telerik team
answered on 25 Oct 2012, 06:29 AM
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.

0
Paul
Top achievements
Rank 1
answered on 28 Mar 2013, 11:48 PM
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
0
Dimitrina
Telerik team
answered on 01 Apr 2013, 01:08 PM
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.

0
Dimitrina
Telerik team
answered on 02 Apr 2013, 11:35 AM
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.

0
Al
Top achievements
Rank 1
answered on 29 Aug 2017, 01:51 AM
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?
0
Dilyan Traykov
Telerik team
answered on 31 Aug 2017, 01:25 PM
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.
Tags
ExpressionEditor
Asked by
Brian
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Brian
Top achievements
Rank 1
Vlad
Telerik team
Paul
Top achievements
Rank 1
Dimitrina
Telerik team
Al
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or