# Common Pie Chart scenarios: Displaying numbers and percentages in a pie chart legend

Some formulas are used more often than others when building Klips. In this series of articles, a Klip is built using a common set of formulas to give a better understanding of how these formulas work within a sample data set.

The pie chart component allows you to compare individual values in relation to the whole.

In this example, the total values for each fruit type are displayed as a number and a percentage in the legend of a pie chart. ## Summary of formulas

For the Values sub-component:

`GROUPBY( A:A , B:B ) / SUM( B:B , data)... `

For the Labels sub-component:

`CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B , method ) , 0 , separator ) ")" , data ) `

## Step 1: Building and configuring a pie chart

1. Click the Build a New Klip button.
2. Select the Pie Chart component.
3. Select Use an existing data source form the library and select our sample data set.
4. Select the Klip component and in the Properties panel, enter a name for the Klip Title.

### For our example

With the Values sub-component selected, select the Data panel. Select Insert function, Data Manipulation, GROUPBY.
The GROUPBY function allows you to return a list of fruit types and sum related values.
`GROUPBY( values , measure , method )`
With values selected. Select column A , the column listing the fruit types. `GROUPBY( A:A , measure , method )`
With measure selected. Select column B, column listing the fruit values. `GROUPBY( A:A , B:B , method ) ...`
With ... selected. Select the mathematical operator /. `GROUPBY( A:A , B:B ) / ... `
With ... selected. Select Insert function, SUM. `GROUPBY( A:A , B:B ) / SUM( data ) ... `
With data selected. Select column B. `GROUPBY( A:A , B:B ) / SUM( B:B , data )... `

### For our example

With the Labels sub-component selected, select the Data panel. Select Insert function, Data Manipulation, GROUP.
The GROUP function returns a unique list of fruit type names.
`GROUP( values )`
With values selected. Select column A, the column listing the fruit. `GROUP( A:A )`
In the formula editing toolbar, with the word GROUP selected. Select Wrap current value in function, Text, CONCAT.
The CONCAT function joins two values together.
`CONCAT( GROUP( A:A ) data )`
With data selected. Select the Insert literal string or number button and type space ( and click the Apply button. `CONCAT( GROUP( A:A ), " (" , data )`
With the Values sub-component selected. Copy the GROUPBY formula you created above using the keyboard combination Ctrl+C.  GROUPBY( A:A , B:B , method ) ...
With the Labels sub-component selected, in the formula editing toolbar, select data . Paste the GROUPBY formula you copied above using the keyboard combination Ctrl+V. `CONCAT( GROUP( A:A ), "(" , GROUPBY( A:A , B:B , method ) , data ) `
With data selected. Select the Insert literal string or number button and type space ) and click the Apply button. `CONCAT( GROUP( A:A ), "(" , GROUPBY( A:A , B:B ) , ")" , data) `
In the formula editing toolbar, with the word GROUPBY selected. Select Wrap current value in function, Text, NUMBERFORMAT.
The function NUMBERFORMAT rounds the number from 60.0 to 60.
`CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B , method) , precision , separator ) , ")" , data ) `
With precision selected. Select the Insert literal string or number button and type 0 (zero) and click the Apply button. `CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B ) , 0 , separator ) , ")" , data ) `

## Step 2: Setting property formats

• Select the Values sub-component, Properties panel, for Format as, select Percentage.
• Select the Labels sub-component, Properties panel, for Format as, select Text.

## Step 3 : Setting the Pie Chart properties

• Select the Pie Chart component, Properties panel, select an option for Size, Max Slices, Sort Order, and Labels.

## Step 4: Troubleshooting

• Use the Evaluate current selection button to verify that columns A and B contain the same number of items.
• If the data source contains a row header, wrap all references to columns in the SLICE function. For more information, see Slice Function