Jump to content
We've recently updated our Privacy Statement, available here ×
  • Creating a percent of a Column using AdHoc designer calculated measures


    Raphaël Peguet
    • Features: Ad Hoc, JasperReports Server Version: v6.3.0 Product: JasperReports® Server

    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
    Joe1236.36%
    Jack824.24%
    Jill1339.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'.

    ScreenShot2016-09-15at17_06_10.png.8ecf4da7363303f6a9de5bbc05e9f7b8.png  

    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.

    SummaryCalculation.png.ec7e61e618e2a63afb1d8a6c7ad16906.png

    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:

    1. Go to <JRS WAR file>/WEB-INF/bundles 

    2. Edit adhoc_masks.properties 

    3. Add new masks to int and decimal like this: 

      ADH_100_MASK_int_4 = #.##%
      ADH_100_MASK_dec_5 = #.##%
      
    4. 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.

    ScreenShot2016-09-15at17_13_56.png.0f8dbec0167b1f9f766a1ca97da3b81a.png

    ScreenShot2016-09-15at17_06_10.png.73284fdea856e87ceaaa691b5966e6ce.png

    ScreenShot2016-09-15at17_13_56.png.c7a213ba768c3c0e7ea6eeb6f774b34f.png


    User Feedback

    Recommended Comments

    First of all, we are running Jasperreports Server 8.x.x and did not have this configuration, which supposedly started with 6.3.  We added the mask entries mentioned in this article, restarted our server, and did not see the new mask entries.  The PercentOf formula does not produce output containing percent signs and the format options do not include the integer and decimal percent options.

    Link to comment
    Share on other sites



    Guest
    This is now closed for further comments

×
×
  • Create New...