# Calculate the difference between rows

#### Step 1: Import Daily Stock Prices&#x20;

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.&#x20;

To follow along, download the data here.&#x20;

{% file src="<https://2294704369-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP_U5ZCmiamDOXEOOTC%2Fuploads%2FpRuYOSmonQmOzNh8PrP2%2FDailyStockPrices.csv?alt=media&token=1eb32364-662d-4535-98e3-f28ba469c857>" %}

<figure><img src="https://2294704369-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP_U5ZCmiamDOXEOOTC%2Fuploads%2F5SDbu9TuKQpSyIcbiB44%2FScreenshot%202023-03-19%20at%2012.27.46%20PM.png?alt=media&#x26;token=d40de7d8-ca78-437a-a857-22fa633ee0f0" alt=""><figcaption><p>Import data into Mito</p></figcaption></figure>

#### Step 2: Create a new column&#x20;

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

<figure><img src="https://2294704369-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP_U5ZCmiamDOXEOOTC%2Fuploads%2F7NMjOV1VpB1y6i25Vxaa%2FScreenshot%202023-03-19%20at%2012.29.46%20PM.png?alt=media&#x26;token=6ba631c7-3d68-4556-884e-c4485fdc2b71" alt=""><figcaption><p>Add a new column</p></figcaption></figure>

#### 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.&#x20;

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)
```

<figure><img src="https://2294704369-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP_U5ZCmiamDOXEOOTC%2Fuploads%2FFY0JYX1MoYcr4Gu3TBVB%2FScreenshot%202023-03-19%20at%2012.30.42%20PM.png?alt=media&#x26;token=4816b2ab-94fa-4990-8455-c56bc1c1d8a6" alt=""><figcaption><p>Calculate the difference between daily stock prices</p></figcaption></figure>

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

<figure><img src="https://2294704369-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP_U5ZCmiamDOXEOOTC%2Fuploads%2F5792Tu31kGAttj9BEnS3%2FScreenshot%202023-03-19%20at%2012.33.10%20PM.png?alt=media&#x26;token=c8a5414b-9358-4bcf-82b4-ae0f303c8d37" alt=""><figcaption><p>View the results</p></figcaption></figure>

For more information on Mito spreadsheet formulas, check out the [spreadsheet formula reference](https://docs.trymito.io/how-to/interacting-with-your-data).&#x20;
