# Is there a way to create a table consisting of multiple measures with aggregate values?

**URL:** <https://community.amazonquick.com/t/is-there-a-way-to-create-a-table-consisting-of-multiple-measures-with-aggregate-values/13428>\
**Category:** Q&A\
**Tags:** calculations, quick-sight\
**Created:** [May 15, 2023, 1:31am UTC](https://community.amazonquick.com/t/is-there-a-way-to-create-a-table-consisting-of-multiple-measures-with-aggregate-values/13428 "2023-05-15T01:31:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![c.ross](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@c.ross](https://community.amazonquick.com/u/c.ross)\
**Post date:** [May 15, 2023, 1:31am UTC](https://community.amazonquick.com/t/is-there-a-way-to-create-a-table-consisting-of-multiple-measures-with-aggregate-values/13428/1 "2023-05-15T01:31:51Z")

</div>

So I have a dataset that consists clinic A, clinic B, clinic C etc, for various years (i.e. 2019,2020,2021,etc). There are measures that consists of aggregated counts for various ranges (0-50, 51-100,101-150, 150-beyond) for each clinic and year.

So let’s say Clinic A has values of 40 between 0-50,50 between 51-100, 30 between 101-150 and 20 with 150 or more.

I need to create a table that both displays the values between the various ranges, which is simply just including the measure associated with each range. However, I then need to create a column consisting of the percentage of each range where the denominator are the sum of the ranges. So 0-50 for example is 40/140,51-100 is 50/140,etc.

Is there a technique anyone might recommend, outside of having to create a calculated field for each range?

If any further explanation is needed, would be happy to provide. Additionally, once the percentages are calculated, will also need to create a pie chart with the percentage of ranges as well.

In Summary:  
Dataset  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/c/c5b7a6b8a6727f8425aed667558fbcd881737b5f.png)

Desired Output:  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/9/9d9a0d2371d41a90350aa6753df0c0125d448e97.png)

Where the % is using the Sum of 0-beyond as the denominator (Sum of 4 aggregate measures essentially)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [May 16, 2023, 2:06pm UTC](https://community.amazonquick.com/t/is-there-a-way-to-create-a-table-consisting-of-multiple-measures-with-aggregate-values/13428/2 "2023-05-16T14:06:38Z")

</div>

I would suggest using SQL to pivot your columns into rows.

> **[Using PIVOT and UNPIVOT - SQL Server](https://learn.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver16)**
>
> Transact-SQL reference for PIVOT and UNPIVOT relational operators. Use these operators on SELECT statements to change a table-valued expression into another table.

Where then you would have  
clinic | year | range | count  
clinic A | 2019 | 0-50 | 40  
Clinic A | 2019 | 51-100 | 50  
etc…

Then it would be really simple as you would just add the range as a row in a table and sum the counts / take a percentage of total on the sum of the counts.
