Since TIBCO JasperReports® Server v.5.6 and later it became much simple to create complex calculated measures using the AdHoc designer. In this article, we will cover how to calculate percentages in an AdHoc View and then an AdHoc report.
Name | # Of Hours Worked | % of |
Joe | 12 | 36.36% |
Jack | 8 | 24.24% |
Jill | 13 | 39.39% |
Add a New Calculated measure
The percentage is calculated using the function PercentOf.
PercentOf is a function that takes 2 parameters and returns the percentage value. The measure that is used to calculate the percentage and the level to define at which level the total should be calculated for the percentage. You may group your data by a category in which case you could calculate the percentage within each category. Often, percentages are calculated on all data which can be done with level='Total'.
This will define the calculation for the detail rows. Note we divide the result of the function by 100, this is needed to be then displayed with a percent sign. To define what should be done for the summary field, there is a Summary Calculation tab.
By default, you may define AggregateFormula but be careful the average of category averages may not be the same as the overall average.
Adding a percent sign (%)
Until TIBCO JasperReports Server v6.3, the '% mask' is not there by default.
To add new masks to the list of ad hoc data formats please do the following:
Go to <JRS WAR file>/WEB-INF/bundles
Edit adhoc_masks.properties
Add new masks to int and decimal like this:
ADH_100_MASK_int_4 = #.##% ADH_100_MASK_dec_5 = #.##%
Restart server
ADH_100_MASK_int_0 = #,##0 ADH_100_MASK_int_1 = 0 ADH_100_MASK_int_2 = $#,##0;($#,##0) ADH_100_MASK_int_3 = #,##0;(#,##0) ADH_100_MASK_int_4 = #.##% ADH_100_MASK_dec_0 = #,##0.00 ADH_100_MASK_dec_1 = 0 ADH_100_MASK_dec_2 = $#,##0.00;($#,##0.00) ADH_100_MASK_dec_3 = $#,##0;($#,##0) ADH_100_MASK_dec_4 = $#,##0.000############# ADH_100_MASK_dec_5 = #.##%
Result
Once the Mask is applied, you will have the percentage for each row and for the summary field.
Recommended Comments