Excel Consecutive Formula

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi -

I have 3 columns of data that holds

Date, contact number and answered which will have Yes or No (Data is sorted)
Im trying to figure out how to look at the number and get the consecutive number of times the word Yes appears before there is a No
So find the No in answered column for that contact number and count how many times above that there is a Yes or put a 1 next to it

And then it will need to reset and look at the next batch for that contact number - I can have helper columns if that helps

Eg say i have this scenario



Date….Contact No…Answered…Result to show

01/01…..0789………….Yes

01/01…..0789………….Yes

01/01…..0789………….No…….1

01/01…..0789………….Yes……Reset here as it was answered so put a 2

01/01…..0789………….Yes

01/01…..0789………….No…….1

01/01…..0789………….No…….1

01/01…..0789………….No…….1

01/01…..0789………….Yes……Reset here as it was answered so put a 2

01/01…..0789………….No

01/01…..0789………….No

01/01…..0789………….No



No further answered calls so leave blank so essentially im trying to find all the answered where it shows yes and then put a 1 for all the No above it



Hope this makes sense



I tried this with no luck



=IF(B2<>B1,"",IF(C2="No","",IF(C2="Yes",IF(COUNTIF(INDEX($C$2:C2,MATCH(B2,$B$2:B2,0)):C2,"No")>0,2,1),"")))

So essentially how many No were there before a yes - put a 1 in the cell and 2 to denote it resets there ie answered at that point where it shows yes..

Result should be like screenshot


IMG_6523.jpeg
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hey no i wont know where the last row will be

All im interested in show put a 1 at each occurence of a No where there is a Yes at some stage after it so if there is a yes - put a 1 at each occurence of No above it

If there is a yes followed by yes i ain’t interest in those 1s nor am i interested in the 1s that dont have a yes after the No

So essentially give me all the contacts that had a yes after a no and mark a 1 against the no and 2 at the point there is a yes
 
Upvote 0
Hey no i wont know where the last row will be

All im interested in show put a 1 at each occurence of a No where there is a Yes at some stage after it so if there is a yes - put a 1 at each occurence of No above it

If there is a yes followed by yes i ain’t interest in those 1s nor am i interested in the 1s that dont have a yes after the No

So essentially give me all the contacts that had a yes after a no and mark a 1 against the no and 2 at the point there is a yes
Okay, I figured that was the case. I have it working down to the last No's without any more answers for that number.. Not sure how to handle those yet. I will keep at it though.
 
Upvote 0
Okay, this is what I came up with:

The "COUNTIFS" looks up to 4 rows ahead of where the formula is to check if there are any more "Yes" results for the current number, if there are not, then it will return 0 and will not enter a 1 for those rows that have "No". The downside to this is you have to have some idea of the longest possible run of "No's" and adjust the "COUNTIFS" range to accommodate it. If the longest possible run could be 6 "No's" then you would change the ranges to be "B2:B7" and "C2:C7" accordingly. Let me know how that works for you.
Book1
ABCD
1DateContact #AnsweredResult
21/1/20240789Yes 
31/1/20240789Yes 
41/1/20240789No1
51/1/20240789No1
61/1/20240789No1
71/1/20240789Yes2
81/1/20240789Yes 
91/1/20240789No1
101/1/20240789Yes2
111/1/20240789Yes 
121/1/20240789Yes 
131/1/20240789Yes 
141/1/20240789No1
151/1/20240789Yes2
161/1/20240789Yes 
171/1/20240789No1
181/1/20240789No1
191/1/20240789No1
201/1/20240789Yes2
211/1/20240789Yes 
221/1/20240789No1
231/1/20240789No1
241/1/20240789Yes2
251/1/20240789No 
261/1/20240789No 
271/1/20240788Yes 
281/1/20240788No1
291/1/20240788Yes2
Sheet6
Cell Formulas
RangeFormula
D2:D29D2=IF(B2<>B1,"",IF(AND(C2="Yes",C1="No"),2,IF(AND(COUNTIFS(B2:B6,B2,C2:C6,"Yes")>0,C2="No",B2=B3),1,"")))
 
Upvote 0
Thank you - with the example above if you look at row 25,26,27
I would have expected to see 1,1,2 as there is a No, No, Yes

The other thing i need to account for is if the contact number changes then it needs to almost reset and do same thing for that contact number, not sure if the formula takes that into account
 
Upvote 0
apologies- think it works as just saw the contact numbers were different

Really appreciate it
 
Upvote 0
Hey it looks like it doesn’t work 100%

Look at example below - it looks like when numbers change it shows a blank so if there is a call that has no followed by a yes, it misses the 1st 1 but if numbers change and the i have a no, no and then yes it misses the first 1 but catches the 2nd no
 

Attachments

  • IMG_6525.jpeg
    IMG_6525.jpeg
    79.3 KB · Views: 10
Upvote 0
The beginning IF statement was the cause for the first "No" on a number change to be ignored. Give this a try:
Book1
ABCD
1DateContact #AnsweredResult
21/1/20240789Yes 
31/1/20240789Yes 
41/1/20240789No1
51/1/20240789No1
61/1/20240789No1
71/1/20240789Yes2
81/1/20240789Yes 
91/1/20240789No1
101/1/20240789Yes2
111/1/20240789Yes 
121/1/20240789Yes 
131/1/20240789Yes 
141/1/20240789No1
151/1/20240789Yes2
161/1/20240789Yes 
171/1/20240789No1
181/1/20240789No1
191/1/20240789No1
201/1/20240789Yes2
211/1/20240789Yes 
221/1/20240789No1
231/1/20240789No1
241/1/20240789Yes2
251/1/20240789No 
261/1/20240789No 
271/1/20241234No1
281/1/20241234No1
291/1/20241234Yes2
301/1/20241234Yes 
311/1/20241234Yes 
321/1/20241234Yes 
331/1/20241234No 
341/1/20241234No 
Sheet1
Cell Formulas
RangeFormula
D2:D34D2=IF(AND(C2="Yes",C1="No"),2,IF(AND(COUNTIFS(B2:B6,B2,C2:C6,"Yes")>0,C2="No",B2=B3),1,""))
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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