Table calculations enable you to create calculations that operate on the table data returned by a SQL query. This is great for calculating metrics like **percent of previous** and **percent change**. This post will show how to calculate these metrics both down columns and across rows.

## Calculating down columns using `offset()`

The `offest()`

function allows you to refer to other rows in the same column that you are operating in. This is perfect for percent of previous and percent change down columns.

Let’s say you have a table like so:

#### Percent of previous

In order to calculate the percent of previous of **Orders** Count, you can make a table calculation like this:

```
${orders.count} / offset(${orders.count}, -1)
```

This will divide each value in the table by the value in the row above it.

#### Percent change

Percent change can be calculated similarly to percent of previous, except you want to subtract the entire calculation by 1:

```
(${orders.count} / offset(${orders.count}, -1)) - 1
```

These two metrics will yield the following results:

Using **Value Format:** `#0.0%`

will format these values nicely for you. Read more about using value format with table calculations here.

## Calculating across rows using `pivot_offset()`

The `pivot_offset()`

function allows you to refer to different pivoted rows in a calculation. In this case, we will want to use `pivot_offset()`

to refer to the previous column (rather than the previous row as in the example above).

Let’s say we have this table:

#### Percent of Previous

In order to calculate percent of previous across the rows, we can use `pivot_offset()`

in the same way we used `offset()`

above:

```
${orders.count} / pivot_offset(${orders.count}, -1)
```

This will divide each value in the table by the value one row to the left. We get the following table:

#### Percent Change

Again, we can use `pivot_offset()`

the same way we used `offset()`

when calculating down columns:

```
(${orders.count} / pivot_offset(${orders.count}, -1)) - 1
```

This is the same as percent of previous, just subtracted by 1. This gives us these results: