Blog Post

How to Retrieve and Work with Sub-Report Values in Acumatica Report Designer

Published on

Dec 9

Troy Vars

Totals from a Sub-report

Recently, I was working on a report for a client. We had to utilize the sub-report functionality of Acumatica’s report designer. This most often happens because you need different data sources that cannot be aggregated within a single report.

In SQL languages, we utilized subqueries for this. Since this functionality is still in development for the Report Designer and Generic Inquiries, I was leaning toward the Sub-report.

Suggested Articles

The report's primary objective was to compile all the Service Orders (SVOs) and appointment details for a linked Service Contract.  To provide a comprehensive report, Labor, Material, and Travel Expenses should be consolidated. Along with an overview of Contract Revenues and Fixed Asset values.

This meant I would need at least one sub-report to handle the complex calculations happening in this report. As development progressed, I realized that I also needed to pass values summed up in the sub-report into the main report. This proved really simple once I tracked down all the pieces from various sites and blogs. 

Basics: To Add a Subreport

The documentation on sub-reports is thin, but the basics are very simple. Information can be found in the S130 or S150 training manual, depending on the year and version you reference. At the time of writing S150 for 2022R2 pgs 53-57. 

Here is a high-level recap of what I did to get my subreport created.

Navigate to the section of the report you want the subreport to be a part of.

A picture containing text, line, font, screenshotDescription automatically generated

Select the subreport tool to draw a box that will limit the area the subreport can occupy in your main report.

A screenshot of a computerDescription automatically generated

Draw your box.

Now you want to modify the subreport ReportName property and the Name property.

In my case, I give the subreport properties the following values.

My next step is to create a new report that will be the subreport.

A picture containing text, screenshot, font, lineDescription automatically generated

I then create my subreport like any other report in Acumatica.

A screenshot of a computer programDescription automatically generated with low confidence

My main report passes a value from the Main Report to the Sub Report via a parameter called Appointment.

My sub-report then filters the records it gets from Acumatica using the parameter on the filters tab of the schema. 

A screenshot of a computerDescription automatically generated with medium confidence
A screenshot of a computerDescription automatically generated with low confidence

My Sub report runs and does some calculations to provide details of who clocked to the appointment and what their total fixed labor costs was.

This total labor cost is then stored in a variable to be passed back to the main report later.

 Tricks:  To Get the Value Back from a Sub-report

The first challenge is getting your main report to reference the Variable from the sub-report.

In my example, one of the totals I wanted to pass back to the report was the $LaborCost. The following blog posts helped get me 90% of the way there.

https://www.augforums.com/forums/acumatica-report-designer/accessing-subreport-values-in-main-report/

https://www.augforums.com/forums/acumatica-report-designer/passing-variables-from-sub-report-not-resetting-value-when-no-value-in-subreport/

To call the variable from the subreport, I needed to reference $subReport1_LaborCost

$ for Variable, subReport1 for the Name property of my subreport, and LaborCost for the variable name on the report.

Similarly, if I had a second report, I could reference the variable $ExpenseCost from it with the following

$subReport2_ExpenseCost

The next challenge was that when I used this and tried to do calculations with it, Acumatica Report Designer would tell me it didn’t exist. This took much longer to locate, but I finally realized why the value was not being interpreted correctly or causing an error.

This post was the key to helping me understand the issue.

https://community.acumatica.com/reports-and-generic-inquires-115/how-to-use-variable-values-from-a-subreport-in-calculations-with-data-from-main-report-4197

When Acumatica passes the value from the Sub Report to the Main report, it does so as a string/text. If you want Acumatica to use it in any other way, for example, in my Sum(). I needed to convert it to that value even if the Subreport variable is already of that type. 

In the end, my equation to display the total was this:

=Format('{0:N}',CDec($subReport1_LaborCost))

And to Sum up, the Contract level was:

=Format('{0:N}',Sum(CDec($subReport1_LaborCost)))

Formatting it to a 2 decimal place number, summing up the section from the converted decimal number from the passed string value from the summed report.

Written By