# Creating multiple Pie charts in Reporting from the a single named query

**URL:** <https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [February 16, 2025, 9:25pm UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406 "2025-02-16T21:25:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [February 16, 2025, 9:25pm UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/1 "2025-02-16T21:25:30Z")

</div>

Hi all,  
I am trying to setup three pie charts which receives the data from the same named query but the only difference is with the parameter set up for filtering the data in the named query . For Instance, I have a named query called 'DefectsSummary' and the parameters set up within the named query are as follows : canisterNo, enamellerNo, i want to set up one pie chart with canisterNo : 1 and another with canisterNo : 2 , I have already set up a parameter in the report parameter named CanisterNo which is bound to the parameter of the named query. What I want to achieve is to render with the named query parameters for each chart by using only one named query as a datasource.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [February 16, 2025, 10:54pm UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/2 "2025-02-16T22:54:20Z")

</div>

In Reporting, you can define multiple Data Sources. Make 2 or more Data Sources of type "Named Query" and be sure to specify a unique "Data Key" name and enter the parameters you need for each one. Then configure each pie chart to point to the correct data key.

Multiple datasources, same named query.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fb5b8f0171bfa66d9f696d1a601ad20032b12679.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5e27d699b7f13efb04bc4e7dc2cd3ff533528176.png)

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [February 16, 2025, 11:04pm UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/3 "2025-02-16T23:04:12Z")

</div>

is it possible to run one data source for all the charts?

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [February 17, 2025, 12:15am UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/4 "2025-02-17T00:15:16Z")

</div>

Yes, it is possible. Use a script datasource instead and call the named queries there. Assign each response to the queries to a unique data key as described before.

---

<div class="post-metadata">

**Author:** ![kvane](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kvane/32/22228_2.png) [@kvane](https://forum.inductiveautomation.com/u/kvane)\
**Post date:** [February 17, 2025, 2:56am UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/5 "2025-02-17T02:56:43Z")

</div>

In addition to the option of using named queries in a script I recommend you review the nested queries page as you could likely run those queries in a nested query:

> **[Nested Queries | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-data/nested-queries)**
>
> What are Nested Queries?

Scripting:

> **[Scripting Data Source | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-data/scripting-data-source)**
>
> The Script data source allows you to use scripting to add data into a report, or modify existing data. With this data source, you can pull in data from the database and then modify it using a script before pushing it out as a data key for use in the...

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [February 17, 2025, 3:15am UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/6 "2025-02-17T03:15:55Z")

</div>

my named query is like this :

```python
WITH ResultCounts AS (
    SELECT result + ' - ' + defect_area as combined_result, COUNT(*) as result_count
    FROM IGN_EDGE_API_NQ_ENAMEL_INSPECTION_RESULTS 
    WHERE t_stamp BETWEEN :startDate AND :endDate
    AND (
        (ISNULL(:enamellerNo, 0) != 0 AND enameller = :enamellerNo)
        OR (ISNULL(:enamellerNo, 0) = 0)
    )
    AND (
        (ISNULL(:cannisterNo, 0) != 0 AND canister = :cannisterNo)
        OR (ISNULL(:cannisterNo, 0) = 0)
    )
    AND (
        (ISNULL(:partNoFilterList, '') != '' AND part_number IN 
            (SELECT TRIM(UPPER(value)) FROM STRING_SPLIT(:partNoFilterList, ',')))
        OR (ISNULL(:partNoFilterList, '') = '')
    )
    GROUP BY result + ' - ' + defect_area
),
RankedResults AS (
    SELECT 
        hi.t_stamp as inspection_t_stamp,
        hi.result + ' - ' + hi.defect_area as combined_result,
        rc.result_count as result_count
    FROM IGN_EDGE_API_NQ_ENAMEL_INSPECTION_RESULTS hi
    LEFT JOIN part_data pd ON hi.part_number = pd.part_number
    LEFT JOIN IGNITION_DATA.dbo.INSPECTION_DEFECT_TYPE_GROUPS dfct_grp ON dfct_grp.defect_type = hi.result 
    LEFT JOIN ResultCounts rc ON hi.result + ' - ' + hi.defect_area = rc.combined_result
    WHERE hi.t_stamp BETWEEN :startDate AND :endDate
    AND (
        (ISNULL(:enamellerNo, 0) != 0 AND hi.enameller = :enamellerNo)
        OR (ISNULL(:enamellerNo, 0) = 0)
    )
    AND (
        (ISNULL(:cannisterNo, 0) != 0 AND hi.canister = :cannisterNo)
        OR (ISNULL(:cannisterNo, 0) = 0)
    )
    AND (
        (ISNULL(:partNoFilterList, '') != '' AND hi.part_number IN 
            (SELECT TRIM(UPPER(value)) FROM STRING_SPLIT(:partNoFilterList, ',')))
        OR (ISNULL(:partNoFilterList, '') = '')
    )
    AND (
        (ISNULL(:defectsOnly, 0) = 1 AND hi.result != 'PASS')
        OR (ISNULL(:defectsOnly, 0) = 0)
    )
    AND (
        (ISNULL(:defectFilterList, '') != '' AND hi.result IN 
            (SELECT TRIM(value) FROM STRING_SPLIT(TRIM(UPPER(:defectFilterList)), ',')))
        OR (ISNULL(:defectFilterList, '') = '')
    )
),
GroupedResults AS (
    SELECT
        inspection_t_stamp,
        CASE 
            WHEN combined_result LIKE '%-H%' THEN 'OTHER'
            ELSE combined_result
        END AS result,
        result_count,
        ROW_NUMBER() OVER (
            PARTITION BY 
                CASE 
                    WHEN combined_result LIKE '%-H%' THEN 'OTHER'
                    ELSE combined_result
                END
            ORDER BY inspection_t_stamp DESC
        ) AS group_rank
    FROM RankedResults
)
SELECT 
    result,
    SUM(result_count) AS total_count
FROM GroupedResults
WHERE group_rank = 1
GROUP BY result
ORDER BY SUM(result_count) DESC

```

where what i want to do is to control the value of the parameters 'enamellerNo' and 'cannisterNo' for each plot. Is there a way in nested query to set the value of the params for each instance and bind that data key to the respective graph.

---

<div class="post-metadata">

**Author:** ![kvane](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kvane/32/22228_2.png) [@kvane](https://forum.inductiveautomation.com/u/kvane)\
**Post date:** [February 17, 2025, 6:35am UTC](https://forum.inductiveautomation.com/t/creating-multiple-pie-charts-in-reporting-from-the-a-single-named-query/102406/7 "2025-02-17T06:35:53Z")

</div>

With a Table Group and nesting within a query that starts with selecting all :cannisterNo and :enamellerNo options, you can likely achieve something like that yes. For a query like that, I would recommend you first practice with Table Grouping/Nesting using this example:

> **[Table Groups | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-design/report-table/table-groups#using-child-tables---an-example)**
>
> Table groups are a single component that contains many tables, each with its own unique data. There are two types of Table Groups you can create within a Table component: Peer Tables and Child Tables. Peer Table Groups allow the second table to begin...

Use the dataset the User Manual mentions from the Nested Queries example, and then you can setup the simple Table Group example. To start mapping it to your case substitute the EquipmentID with your IDs.
