I have a database with 3 columns (code, week, value), where code is project code, week is the date of the beginning of the week and value is the aggregate amount for the respective week.

For each project, I have to determine a performance trend line coefficient for a certain period (e.g. the last 4 weeks since the beginning of 2020).

```
INDEX(LINEST(LN(Values),LN({1,..,N})),1)
```

where N is the number of weeks from the start (e.g. 4 for the last 4 weeks)

My problems started with trying to do this for a number of projects.

I only found a solution for one project (example for the last 4 weeks, others in the file), but there is a way to do it for all projects.

```
=IFERROR(INDEX(
LINEST(
LN(
VLOOKUP(
SORT(
LARGE(UNIQUE(FILTER(DB!$B:$B,DB!$A:$A = A2)),
SEQUENCE(4,1,2,1)),1,true),
QUERY({DB!$A:$C},
"Select Col2, SUM(Col3)
Where Col1 ='"&A2&"'
Group by Col2
Order by Col2
Label SUM(Col3) ''",0),
2,0)
),
LN(
SEQUENCE(4,1,2,1)
)),
1),0)
```

Here is Test_Doc,

Thank you in advance.