Calculate the difference between rows

A step-by-step guide to referencing a previous row in a spreadsheet formula.

Step 1: Import Daily Stock Prices

In this example, we have daily stock prices for a bunch of different stocks. We want to calculate the daily change in stock price for each stock.

To follow along, download the data here.

Step 2: Create a new column

We're going to use a spreadsheet formula to calculate the daily change in stock price. Create a new column for the formula.

Step 3: Write the spreadsheet formula

To calculate the daily change in stock price, compare each row to the previous row. If they have the same stock symbol, calculate the difference in stock price. Otherwise, set the daily price change to zero.

If we write the formula in row 1 of the Daily Price Change column, then the formula should look like this:

IF(Symbol1==Symbol0, Close1-Close0,0)

Step 4: View the results

Once the formula is applied, check out the results. Notice that the first row has a daily price change of zero because there was no previous stock price to compare.

For more information on Mito spreadsheet formulas, check out the spreadsheet formula reference.

Last updated