# How to Calculate Percentages In Workbooks (also applies to complex subtotals)

Imagine that we have Sales orders, that we are aggregating in a pivot by City, State and Country, and we are asked to calculate the percentage of Sales of a given State within a Country.

In order to do that, we need two calculated fields:

[Sales by State]
[Sales by Country]

Now, since our pivot shows Sales by City, State and Country, just placing Sum(Sale Amt) into a pivot row will aggregate Sales by City, State and Country. But how would I go about aggregating Sales at a higher level, like by Country or by State?

To accomplish that, we need to start from a Table visualization. Table visualizations in Sigma are special, because, unlike pivots and charts, they allow us to define multiple aggregation levels (aka grouping levels) and use them to set aggregation context for calculated fields.

So, the general approach to calculating percentages or complex subtotals is:

Step 1. Start by using a table visualization, create grouping levels and calculated fields on those levels.
Step 2. Create a pivot / chart, as a child of the table from Step 1, to visualize the result.