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

using Column AVG and custom function

2 Answers 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 05 Feb 2013, 07:44 PM
I use the below custom function to convert the numeric value in my Risk column to its text equivalent.

= ReturnRiskLeveltext(Fields.RiskLevel)
public static string ReturnRiskLeveltext(int rId)
{
    using (DataEntities ctx = new DataEntities())
    {
        var RiskLevel = ctx.RiskLevels.Where(x => x.RiskLevelID == rId).SingleOrDefault();
        return RiskLevel.Level;
    }
}

However, in the footer row I wish to display an Average Risk Level
= Avg(Fields.RiskLevel)

Would be correct because it returns a 2. however, I wish to again display the Text equivalent.
= ReturnRiskLeveltext(Avg(Fields.RiskLevel))

Throws an error 'An error has occurred while processing TextBox 'textBox11': The expression contains undefined function call ReturnRiskLeveltext().'

Ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 06 Feb 2013, 12:50 PM
Hello Tim,

The return type of the average aggregate is determined by the type of the evaluated result of expression. So if it returns type different than int specified as argument type of your user function, it would throw this error. You can change it to object and use appropriate cast in the user function directly or debug to determine the proper type and change the type of the argument.

Greetings,
Steve
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Tim
Top achievements
Rank 1
answered on 07 Feb 2013, 02:36 PM
I got this working with a simple CAST

= ReturnRiskLeveltext(CInt(Avg(Fields.RiskLevel)))
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Steve
Telerik team
Tim
Top achievements
Rank 1
Share this question
or