I have a simple spreadsheet, where column A is a bunch of dates (ascending) and column B is a bunch of values. Finding the OLS slope is easy:

```
SLOPE(B2:B161,A2:A161)
```

But I don’t want the slope of everything. I want to see the slope for each month. So if C3 is “3”, I’d want to do something like:

```
SLOPE(IF(MONTH(A2:A161)==C3,B2:B161), A2:A161)
```

Which is wrong, but hopefully conveys what I’m trying to do. How do I actually do this?

You’ve got the right idea more or less. Try the following, but instead of just pressing enter to commit the value to the cell, press Control+Shift+Enter (CSE) which turns it into an array formula and makes it behave the way you’d like.

```
=SLOPE(IF(MONTH(A2:A161)=3,A2:A161),B2:B161)
```

Tags: excelexcel