ActiveReports 18 .NET Edition
Report Authors / Design Reports / Design Section Reports / Tutorials: Section Report Scenarios / Create Top N Report
In This Topic
    Create Top N Report
    In This Topic

    In a Section report, in order to display only the top N number of rows or records on a report, you can manipulate the data in query, or use script depending on the data source. Let's see the working example for a report bound to an Sqlite data source. Your data will be more meaningful if you also specify the order of rows.

    1. Create a new Section report and bind the data to 'reels.db'. See Custom Data Provider topic for more information. The data source connection string will be as follows:
      Data Source Connection String
      Copy Code
      data source = C:\Data\reels.db
      

    2. In the Report Data Source dialog, paste the following SQL query in the Query field to fetch Top 10 records from the database, ordered by user rating from highest to lowest:

      Sqlite

      Query
      Copy Code
      SELECT * FROM Movie Order By UserRating Desc LIMIT 10
      

       

    3. Then click OK to close the dialog.
    4. In the Report Explorer, expand the Fields node, then the Bound node.
    5. Drag and drop the following fields onto the detail section and set the properties of each textbox as indicated.
      [Title]
      [YearReleased]
      [UserRating]
    6. Drag-drop a Label controls in the PageHeader section for labeling the details in the Detail section, and for the report heading.

      Top N Report Design View 
    7. Preview the report. You will notice only 10 number of records displaying in your report. The following image illustrates Top N Report displaying top 10 movie records:
      Top N Report at Run Time

    The following sections provide sample queries or script that must be used to obtain top N data for other data sources.

    OLEDB, ODBC, SQL

    Query
    Copy Code
    SELECT Top 10 * FROM Movie
    

    XML

    Query
    Copy Code
    //countries/country[position() <= 10]
    

     

    JSON

    Query
    Copy Code
    $.Customers[:10]
    

     

    CSV

    Script
    Copy Code
    int i = 1;
    public bool ActiveReport_FetchData(bool eof)
    {
        return i++ > 10;
    }
    public void ActiveReport_ReportEnd()
    {
        i = 0;   
    }