10 Answers, 1 is accepted
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
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
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
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
You can check this article for more info about aggregates methods:
http://msdn.microsoft.com/en-us/library/bb548651.aspx
Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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