---
title: Example - creating a simple report
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

This example demonstrates how to create a report that displays a table, graph and value, and uses a reporting parameter:

## Creating a report category

1. Open the **Reporting** application.
2. Select the root of the reporting tree (the **All reports** category by default).
3. Click **...** next to the **New report** button and select **New category**.
4. Type _User reports_ as the **Category display name**.
5. You can leave the code name as _(automatic)_.
6. Click **Save**.

## Creating a new report

1. In the **Reporting** application, click **New report**.
2. Type Pages by page template as the **Report display name**.
3. Click **Save**.
   - Now you can edit the layout of the report and insert tables, graphs and values.
   - The **General** tab of the report editing interface opens.
4. Type _Pages by page template_ into the **Layout** text area.
5. Select the text and use the editor to set the **Format** to _Heading 1_.

   ![Adding the heading into the report's layout](https://docs.kentico.com/docsassets/k10/example-creating-a-simple-report/New_Report.png "Adding the heading into the report's layout")
6. Click **Save**.

### Creating a new table

1. On the report's **General** tab, click **New** in the **Tables** section below the layout editor.
2. Enter the following values:
   - **Display name:** Pages by Page Template
   - **Query:**

     ```sql

     SELECT PageTemplateDisplayName AS [Template Name], DocumentNamePath AS [Page]
      FROM View_CMS_Tree_Joined
      LEFT JOIN CMS_PageTemplate 
      ON CMS_PageTemplate.PageTemplateID = View_CMS_Tree_Joined.DocumentPageTemplateID
      WHERE PageTemplateDisplayName IS NOT NULL AND PageTemplateIsReusable = 1 
      ORDER BY PageTemplateDisplayName

     ```
   - **Is stored procedure:** no
   - **SkinID**: ReportGridAnalytics
   - **Enable paging**: yes (checked)
   - **Page size**: 10
   - **Page mode**: Page numbers
3. Click **Save & Close**.
4. Place the cursor in the layout editor on a new line under the heading.
5. Select the table from the list in the **Tables** section.
6. Click **Insert**.
   - The system adds a string like _%%control:ReportTable?PagesByPageTemplate.PagesByPageTemplate%%_ into the text area.
7. Click **Save**.

Switch to the **View** tab to see the report table.

![Viewing the new report table](https://docs.kentico.com/docsassets/k10/example-creating-a-simple-report/Report_Table.png "Viewing the new report table")

### Creating a new graph

1. Switch back to the report's **General** tab.
2. Click **New** in the **Graphs** section below the layout editor.
3. Enter the following values:
   - **Display name:** Favorite Page Templates
   - **Query:**

     ```sql

     SELECT TOP 5 PageTemplateDisplayName AS [Template Name], COUNT(PageTemplateDisplayName) AS [Usage]
      FROM View_CMS_Tree_Joined
      LEFT JOIN CMS_PageTemplate 
      ON CMS_PageTemplate.PageTemplateID = View_CMS_Tree_Joined.DocumentPageTemplateID
      WHERE PageTemplateDisplayName IS NOT NULL AND PageTemplateIsReusable = 1
      GROUP BY PageTemplateDisplayName
      ORDER BY COUNT(PageTemplateDisplayName) DESC

     ```
   - **Graph type**: Pie chart
   - **Drawing style**: Pie
   - **Title**: Favorite page templates
   - **Series -> Display item value**: Disabled (not checked)
4. Click **Save & Close**.
5. Place the cursor in the layout editor on a new line under the table.
6. Select the graph from the list in the **Graphs** section.
7. Click **Insert**.
   - The system adds a string like _%%control:ReportGraph?PagesByPageTemplate.MostFavoritePageTemplates%%_ into the text area.
8. Click **Save** to save the changes.

 If you now switch to the **View** tab, you can see the report graph.

![Viewing the new report graph](https://docs.kentico.com/docsassets/k10/example-creating-a-simple-report/Report_Graph.png "Viewing the new report graph")

### Creating new values

1. Switch back to the report's **General** tab.
2. Click **New** in the **Values** section below the layout editor.
3. Enter the following values:
   - **Display name:** Number of pages with page template
   - **Query:**

     ```sql

     SELECT COUNT(DocumentID)
      FROM View_CMS_Tree_Joined
      WHERE DocumentPageTemplateID IS NOT NULL

     ```
   - **Is stored procedure**: no
   - **Formatting string**: Pages with template: {0}
4. Click **Save & Close**.
5. Place the cursor in the layout editor under the graph.
6. Select the new value from the list in the **Values** section.
7. Click **Insert**.
   - The system adds a string like _%%control:ReportValue?PagesByPageTemplate.NumberOfPagesWithPageTemplate%%_ into the text area.
8. Click **Save**.

 If you switch to the **View** tab, you can see the text of the value.

## Defining report parameters

1. Switch to the **Parameters** tab.
2. Click **New field** and enter the following values:
   - **Field name:** UserID
   - **Data type:** Integer number
   - **Default value:** 53
   - **Field caption:** Created by user
   - **Form control:** User selector
3. Click **Save**.

Now you need to add the parameter to your queries. For the purposes of this example, modify only the table query.

1. Switch to the **General** tab.
2. Select **Pages by page template** in the **Table** list.
3. Click **...** next to the **New** button and select **Edit**.
4. Modify the table SQL query like this:

   ```sql

   SELECT PageTemplateDisplayName AS [Template Name], DocumentNamePath AS [Page]
    FROM View_CMS_Tree_Joined
    LEFT JOIN CMS_PageTemplate
    ON CMS_PageTemplate.PageTemplateID = View_CMS_Tree_Joined.DocumentPageTemplateID
    WHERE PageTemplateDisplayName IS NOT NULL AND DocumentCreatedByUserID = @UserID
    ORDER BY PageTemplateDisplayName

   ```

   > **Info:** This adds the parameter to the WHERE condition of the query. All parameters that you define can be used in the query using the @ expression.
5. Click **Save & Close**.

Now switch to the **View** tab. You can see that the report has a filter:

![Viewing the filter that allows you to set value of the report's parameter](https://docs.kentico.com/docsassets/k10/example-creating-a-simple-report/Report_Filter.png "Viewing the filter that allows you to set value of the report's parameter")

The table now only displays template names of pages that were created by the user specified in the filter.
