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

using textbox expression to calculate other textboxes

7 Answers 501 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dario
Top achievements
Rank 1
Dario asked on 14 Oct 2011, 05:05 PM
Hi there,   
   I'm new to Telerik reporting and I'm haveing a problem with the expressions. I have 3 textboxes with number values and 1 other textbox that woill be the total of the 3. But when I run the report it gives me an error "The expression contains object "fldMMHQ_USD" that is not defined in the current context". I don't understand. The textbox is there, I see the values, but the "Total" textbox doesn't seem to the others. Here is my expression: = fldMMHQ_USD + fldMM_USD + fldEMPR_USD. Thanks for the help

7 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 19 Oct 2011, 02:06 PM
Hello Dario,

I suppose you have 3 TextBox items in your report which are data-bound to 3 different fields from a data source. To compute the sum of them via an expression, you need to specify the fields from the data source in the expression, not the TextBox items. For example, lets assume you have the following 3 fields in the data source: Field1, Field2, Field3; and you have the following 3 TextBox items in the report: TextBox1, TextBox2, TextBox3.

Item
Field
Expression
TextBox1
Field1
= Fields.Field1
TextBox2
Field2
= Fields.Field2
TextBox3
Field3
= Fields.Field3

In this case the correct expression syntax to sum the 3 fields would be the following one:

= Fields.Field1 + Fields.Field2 + Fields.Field3

A more detailed explanation about using expressions can be found in the next section of the online documentation: Expressions. Please, pay close attention to the following help topic in the same section which discusses the global objects recognized by the expression engine and the correct syntax how to access them: Global Objects.

Hope this helps.

All the best,
Ivan
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Dario
Top achievements
Rank 1
answered on 19 Oct 2011, 02:12 PM
They are not bound to any datasource field. I set the value in the code behind.
 Ex: Textbox1.Value = 25.26
       TextBox2.Value = 1.0536

What I want to do in Textbox 3 is as follows:
    Textbox3 = Textbox1.value * Textbox2.value

But I want to do it in the expression and not in the code behind. Hope this explanation is a little more clear. Thanks for the help
0
Ivan
Telerik team
answered on 21 Oct 2011, 01:16 PM
Hi Dario,

I am not quite certain I understand your inquiry correctly. In theory nothing stops you from implementing a user function that finds a specific item in the processing tree by name and use it in your expressions. The problem with this approach is that it is too error prone, because it depends solely on the order the items are being processed by the reporting engine. For example, if TextBox3 is processed after both TextBox1 and TextBox2 your expression would work as expected, however if TextBox3 is processed before TextBox1 or TextBox2 the expression would produce an incorrect result, because TextBox1 or TextBox2 might not have a valid value yet. That is part of the reason why we do not expose the report items directly in expressions.

If you have a hard-coded constant you want to reuse in expressions you can always create a hidden ReportParameter with a default value set to that constant and then use the ReportParameter in the expressions instead. This approach also has the side benefit that you can easily pass a different value for the constant from outside the report.

Best wishes,
Ivan
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Dario
Top achievements
Rank 1
answered on 21 Oct 2011, 02:39 PM
I used to do that in Crystal with realtive ease but I'm having trouble with Telerik. Here's a print-screen of part of my report. If you can help right the expression for the TOTAL field it would really help me out. Thx


  
0
Steve
Telerik team
answered on 26 Oct 2011, 08:41 AM
Hello Dario,

My colleague already provided all the necessary information you need to get this working and similar examples are already present in the Expressions as Values of Item Properties help article. If you're still having problems, it would be best to open a support ticket and attach a sample report that shows what you do, and we would advise you accordingly.

Best wishes,
Steve
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Masaki
Top achievements
Rank 1
answered on 26 Jan 2017, 09:40 PM

Hi Ivan,

I think you provided necessary information to workaround the core issue of this thread, but I still think that there should be a better way.

I have one TextBox that has a bit complicated formula, using SUM, IIF, or COUNT, and I would like to reuse that value in many other TextBoxes. In order to do that I need to have all these TextBoxes include the complicated formula addition to some other values that is unique in each TextBox.

Is there any way I can set the value in a report footer section that can be referred  by other TextBoxes?

0
Stef
Telerik team
answered on 27 Jan 2017, 10:40 AM
Hi Masaki,

You can use a user function that performs the complex calculations and returns the result. Details how to load user functions in the Standalone Report Designer are available in Extending Report Designer.

Please feel free to log a feature request for having re-usable custom expressions in the Expression Editor. Features are considered for implementation based on the demand.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Dario
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Dario
Top achievements
Rank 1
Steve
Telerik team
Masaki
Top achievements
Rank 1
Stef
Telerik team
Share this question
or