# Help with sum function

#### Shweta

##### Well-known Member
Hi All,

 W5 W4 W3 W2 W1 W0 Result 28 L 30 L 22 0 80 8 7 9 11 7 0 27

<colgroup><col span="6"><col></colgroup><tbody>
</tbody>

In the result column, I want the sum for the last 4 weeks. If "L" is written in a column then formula should take the value from the next column but the count of the columns should not exceed 4.

For example in first case 0+22+30+28 = 80
in second case 0+7+11+9 = 27.

Please provide me an appropriate formula for this.

Regards,
Shweta

### Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
For the sample data:

=SUM(OFFSET(F2,0,0,1,-(4+COUNTIF(A2:F2,"L"))))

If there may be less than 4 numbers...try this regular formula:
Code:
``G2: =SUM(F2:INDEX(2:2,INDEX(LARGE((A2:F2<"")*COLUMN(A2:F2),MIN(COUNT(A2:F2),4)),0)))``
Copy that formula down as far as you need.

Is that something you can work with?

Thanks Andrew!

This formula is working perfectly.

Thanks Ron!

This one is also working fine.

Replies
20
Views
502
Replies
3
Views
512
Replies
5
Views
540
Replies
8
Views
382
Replies
2
Views
323

1,196,409
Messages
6,015,106
Members
441,870
Latest member
kojack

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back