Comment on page

# 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.
DailyStockPrices.csv
110KB
Text Import data into Mito

#### 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) Calculate the difference between daily stock prices

#### 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. View the results