Jump to content
We've recently updated our Privacy Statement, available here ×
  • Report tip: Build a top 10 values report displaying "Others" row among the values


    gregd
    • Version: v4.5, v4.5.1 Product: iReport Designer

    What do we want to do?

    The purpose of this article is to give a step by step tutorial to build a report which would display the top 9 values from the datasource and summarise other values in a 10th row. So if we consider that we have the total sales for many customers.

    Our aim here is to build a report which:

    • Show the top 9 customers in terms of total sales figures,
    • As 10th value, calculate the total of all sales for customers which are not in the top 9, that will be to amount for 'Other',
    • Order all 10 values by total customers sales, descending,
    • Highlight the 'Other' with a beautiful color.

    So it will a similar report than this one:

    Report.png.941081b96c31be4e4fba861faffb0a27.png

    Tools and version used for this example

    This example was done using iReport 4.5 on a windows machine. It uses the sample datasource which is shipped with JasperReports Server 4.5.1 (JRS 4.5.1).

    How to, Step by Step

    The key here is to use a XMLA datasource which allows us to query the data with MDX.

    1. Using iReport Designer if you want to preview your report you will have to create and XML/A connection to your server.

      Click on DB_button.png.bdd4e21dabc3e968e08e956c5fb9145b.png

    2. Then you will need to get your data. Open the Query designer by clicking on QueryDesigner_button.png.1217b649075f89575d93de77ff47e11a.png

    3. Select Query language to MDX
    4. 4- And type your query. In our example we use the MDX query:

      with set [TopSelection] 
            as 'TopCount(Filter([Customers].[USA].[CA].Children, 
                                ([Measures].[Store Sales] > 0.0)),
                                Parameter("TopCount", NUMERIC, 9.0,
                                          "Number of Customers to show"),
                                [Measures].[Store Sales])'
        member [Customers].[USA].[CA].[Total] as 'Sum([TopSelection])'
        member [Customers].[USA].[CA].[Other Customers]
            as '([Customers].[USA].[CA] - [Customers].[USA].[CA].[Total])'
        select NON EMPTY {[Measures].[Store Sales]} ON COLUMNS, 
         Order({[TopSelection], [Customers].[USA].[CA].[Other Customers]},
               [Measures].[Store Sales], DESC) 
            ON ROWS from [Sales] 
      

    5. Press Read Fields if the fields are not automatically retrieved (Fields highlighted in the fields section)

      QueryDesigner_screenshot.png.482d5662fe7b9e9b01f512c6022eed3f.png

    6. Then the fields will be listed in the Report Inspector

      ReportInspector_fields.png.10b86ff1d82a145d3723ae9fddaf5b38.png

    7. The last thing will be to Drop your fields in the report.

    Conclusion

    If you have setup the XML/A connection in iReports Designer, then you will be able to preview the report, otherwise deploy it to your server using the Foodmart XML/A Connection which is located by default under /Organization/analysis/connections.

    A Zip file, containing the JRXML of the report used to generate the screenshot below, is attached Top9.zip. It uses the Foodmart XML/A Connection which is included in the samples that are shipped with JasperReports Server v4.5.1. Also an export of Top9_&_other.pdf is attached.

     


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...