Introduction.
Earlier, we solved this problem using a Query in the blog post Percentage on Total Query. This time, let’s see how to achieve the same result on a Report. Our task is to display each detail line’s value as a percentage of the report’s summary total.
The approach is simple:
-
Create a Report that lists the detailed values and includes a report-level summary (such as the total).
-
Insert a Text Box in the Detail section.
-
In the Text Box’s Control Source, write an expression that divides the detail value by the Report Summary total.
This way, each record line will show its proportional contribution to the overall total directly on the Report.
Design a Sample Report to Try.
Import the Order Detail Table from Microsoft Access Sample Database: C:\Program Files\Microsoft Office\Office11\Sample\Northwind.mdb
Open a new Query in SQL View, without selecting a Table from the displayed list.
Copy and paste the following SQL String into the SQL editing window of the new Query:
SELECT [Order Details].[Order ID], Sum([Order Details].Quantity) AS TQuantity, Sum([Order Details].[Unit Price]) AS UnitPrice, Sum([Unit Price]*[Quantity]) AS TotalPrice FROM [Order Details] GROUP BY [Order Details].[Order ID];
Save the Query with the name OrderSummary.
Design a Report (as shown in the image given below) with the Detail Section and Report Footer summary controls using the OrderSummary as the Source.
Click on the Text Box at the Footer of the Report to select it.
Display the Property Sheet (F4 or ALT+Enter) of the Text Box.
Change the Name Property Value to GTPrice (stands for Grand Total Price).
Write the expression =Sum([TotalPrice]) in the Control Source Property.
Select the Text Box at the right end of the Detail Section and display its Property Sheet.
Write the expression =[TotalPrice]/[GTPrice] in the Control Source Property.
In the Format Property, select the Percent format from the drop-down list.
Type 2 in the Decimal Places Property.
Save and Close the Report.
Open the OrderSummary in Print Preview and check the detail line percentage value calculated on the Report Footer Grand Total Price.
Creating Page-Level Totals.
Want to know how to calculate and display Page-wise control totals? You can learn it from here.
No comments:
Post a Comment
Comments subject to moderation before publishing.