Any way to create and reuse/reference group calculated values?

2 Answers 52 Views
Expressions Report Designer - Web
Pascal
Top achievements
Rank 1
Iron
Iron
Pascal asked on 02 Oct 2023, 02:20 PM

Question Details

I have multiple expressions which redo the same calculation several times. 

Part of the calculation uses an aggregated result of a field.

Is there a way to simplify and increase the maintainability of the report by creating a calculated field for a group? This field would be used multiple times in sub-groups and in the detail section.

Please note that I do not have the power to update the source code and because of this I can not create "custom functions". 

I've tried to store the calculated value in an invisible text box but I can't seem to recall this value to be used in subsequent text boxes. 

 

Very Simplified Example

Let f(x) = Avg( Field.x ) <-- How do I set this in the group header so I can reference it in the detail section?

Let textBox7.Value = "Distance From COM: " + Abs( f(x) - Field.x )

 

 

Note: If this is not possible across groups, but it is within a group please let me know. This would also greatly simplify the maintainability of my report. 

 

Thank you for taking the time.

2 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 05 Oct 2023, 10:16 AM

Hi Pascal,

Generally, each Expression in the report is evaluated in the context of the corresponding report item/group - Expression Scope. The calculated values are associated with the particular item/group and cannot be shared with other items/groups. That's why you cannot recall the value from the hidden textbox in other items.

You may use the data scope-related functions to evaluate an expression in a parent data scope.

Regarding the particular example, the Value of textBox7 may be set like this:

= "Distance From COM: " + Abs( Exec('groupNameHere', Avg( Field.x )) - Field.x )

Indeed, you may store a value to be reused through User Functions that don't seem to be an option in your scenario. Unfortunately, I cannot think of an alternative way of sharing values between report items/groups.

Regards,
Todor
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
0
Pascal
Top achievements
Rank 1
Iron
Iron
answered on 06 Nov 2023, 05:00 PM

A workaround I found. 

I realized that the overhead for a sub-report that does not create its own data source (its data source is passed from its parent) is minimal. By adding a "middle layer" or "prepping sub-report" or "wrapper report" or "wrapper layer" (I'm bad with naming things) which could be used to pass additional report parameters to the sub-report which would be common calcluations.

That way if I need the following setup

MainReport.trdp -> SubReport.trdp

Where the report SubReport.trdp accepts report parameters A, B and C and uses the calculation [f(A, B, C) = A^B / C - B^2] multiple times within multiple components. 

 

We could add another sub-report so that we would have MainReport.trdp -> SubReportWrapper.trdp -> SubReport.trdp

Where the SubReportWrapper is only used to take the three parameters (A, B, C) given by the parent report and pass four parameters to the child sub-report (A, B, C, D) where D = f(A, B, C) = A^B / C - B^2.

That way in SubReport.trdp I could simplify expressions that use f(A,B,C) in its expression with input parameter D.

Tags
Expressions Report Designer - Web
Asked by
Pascal
Top achievements
Rank 1
Iron
Iron
Answers by
Todor
Telerik team
Pascal
Top achievements
Rank 1
Iron
Iron
Share this question
or