Table calculations make it easy to create on-the-fly metrics and enable the creation of 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 article will show how to calculate these metrics, down columns and across rows.

## Calculating Down Columns Using `offset()`

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

For an example, see the table below:

### 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:

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 lets you refer to different pivoted rows in a calculation. In this case, you can use `pivot_offset()`

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

For an example, see the table below:

### 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 use `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: