Count number of rows until a value is reached

ondi58

New Member
Joined
Dec 13, 2018
Messages
4
Hi, I've been searching for an answer to this for a while but can't work it out, so I'm calling for help!

(BTW, I'm using Google Sheets)

I've a list of football results, and I'm trying to calculate the longest unbeaten run. Column A shows the result (Won, Lost, Drawn). I'd like column B to increase by 1, for every row until a "Lost" is reached. The "Lost" resets the counter to 0.

Here is an example of what the outcome should be.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Drawn[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Drawn[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Drawn[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]


Thank you so much in advance!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You have to start this in row 2... so use headers in your columns.

=IF(A2="Lost",0,B1+1)
 
Last edited:
Upvote 0
That's perfect, thank you!

Would you know how to do the same, but for the same value to repeat - so the number of times "Won" appears in a row, resetting to 0 when "Drawn" or "Lost" appears. I've tried with this formula, but without luck.

Code:
[COLOR=#000000][FONT=Inconsolata]=[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]IF[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]([/FONT][/COLOR][COLOR=#F7981D][FONT=Inconsolata]I3[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]=[/FONT][/COLOR][COLOR=green][FONT=Inconsolata]"Won"[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata],[/FONT][/COLOR][COLOR=#7E3794][FONT=Inconsolata]J1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata]+[/FONT][/COLOR][COLOR=#1155CC][FONT=Inconsolata]1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata],[/FONT][/COLOR][COLOR=#1155CC][FONT=Inconsolata]1[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata])[/FONT][/COLOR]

(cell references changed for my spreadsheet)

Many thanks
 
Upvote 0
Thank you. However, it's showing the result one row below the last "Won"

Here's what it's showing

[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]Drew[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]1[/TD]
[/TR]
</tbody>[/TABLE]

Here's what I'd like it to show:

[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]Drew[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Won[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Lost[/TD]
[TD]0

[/TD]
[/TR]
</tbody>[/TABLE]

Thanks again so much for your help
 
Upvote 0
You havent said which row the formula is in. Thats the crucial bit. The I2 needs to be the cell to the left of the formula. The J1 needs to be the cell above the formula. Change the 2 and 1 to suit.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top