Mark Adjacent Column if Before or After Reference Date

paulfitz320

Board Regular
Joined
Jan 6, 2007
Messages
126
Office Version
  1. 365
Platform
  1. Windows
Hi,

Stuck with this, would appreciate some help please.

I need a formula for COLUMN I

Start at COL D (Horse) then go across to...
COL H - If it contains a 1 for that horse leave adjacent cell in COL I blank
COL H - If it contains a 2 for that horse put a 4 in COL I (If the date in COL B is AFTER the date where the 1 occured in COL H for that horse)
COL H - If it contains a 2 for that horse put a 3 in COL I (If the date in COL B is BEFORE the date where the 1 occured in COL H for that horse)

wpm hurdles won hurdles debut sp less then 9to2.xlsx
ABCDEFGHI
1CourseDateTimeHorseFin PosHurdle Runs BeforeRace Typehurdle debut ynAfter 1 Next Door
2Punchestown27/04/202117:55Adamantly Chosen10NHF23
3Fairyhouse27/11/202113:01Adamantly Chosen20Hurdle1
4Cork08/01/202213:03Adamantly Chosen21Hurdle24
5Thurles10/02/202214:55Adamantly Chosen12Hurdle24
6Cheltenham18/03/202217:30Adamantly Chosen113Hurdle24
7Punchestown30/04/202217:30Adamantly Chosen44Hurdle24
8Galway28/07/202217:05Adamantly Chosen135Hurdle24
9Listowel19/09/202217:05Adamantly Chosen16Chase24
10Punchestown12/10/202215:55Adamantly Chosen16Chase24
11Fairyhouse04/12/202213:55Adamantly Chosen56Chase24
12Limerick26/12/202214:40Adamantly Chosen26Chase24
13Leopardstown05/02/202313:40Adamantly Chosen26Chase24
14Cheltenham15/03/202314:10Adamantly Chosen76Chase24
15Fairyhouse09/04/202316:55Adamantly Chosen66Chase24
16Punchestown28/04/202316:15Adamantly ChosenPU6Chase24
17Killarney19/08/202216:05Aghaboy20Hurdle1
18Ballinrobe09/09/202215:50Aghaboy11Hurdle24
19Listowel18/09/202214:10Aghaboy12Hurdle24
20Fairyhouse04/12/202212:25Aghaboy73Hurdle24
21Leopardstown26/12/202213:10Aghaboy74Hurdle24
22Galway03/08/202317:40Aghaboy135Turf24
Sheet1
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
what is your tiebreaker rule, "Adamantly Chosen" has multiple 1's in column H? What version of Excel do you use?
 
Upvote 0
Just giving this one a bump.
try this:

Mr excel questions 70.xlsm
ABCDEFGHI
1CourseDateTimeHorseFin PosHurdle Runs BeforeRace Typehurdle debut yn
2Punchestown2021-04-2717:55:00Adamantly Chosen10NHF2 
3Fairyhouse2021-11-2713:01:00Adamantly Chosen20Hurdle1 
4Cork2022-01-0813:03:00Adamantly Chosen21Hurdle24
5Thurles2022-02-1014:55:00Adamantly Chosen12Hurdle24
6Cheltenham2022-03-1817:30:00Adamantly Chosen113Hurdle24
7Punchestown2022-04-3017:30:00Adamantly Chosen44Hurdle24
8Galway2022-07-2817:05:00Adamantly Chosen135Hurdle24
9Listowel2022-09-1917:05:00Adamantly Chosen16Chase24
10Punchestown2022-10-1215:55:00Adamantly Chosen16Chase24
11Fairyhouse2022-12-0413:55:00Adamantly Chosen56Chase24
12Limerick2022-12-2614:40:00Adamantly Chosen26Chase24
13Leopardstown2023-02-0513:40:00Adamantly Chosen26Chase24
14Cheltenham2023-03-1514:10:00Adamantly Chosen76Chase24
15Fairyhouse2023-04-0916:55:00Adamantly Chosen66Chase24
16Punchestown2023-04-2816:15:00Adamantly ChosenPU6Chase24
17Killarney2022-08-1916:05:00Aghaboy20Hurdle1 
18Ballinrobe2022-09-0915:50:00Aghaboy11Hurdle24
19Listowel2022-09-1814:10:00Aghaboy12Hurdle24
20Fairyhouse2022-12-0412:25:00Aghaboy73Hurdle24
21Leopardstown2022-12-2613:10:00Aghaboy74Hurdle24
22Galway2023-08-0317:40:00Aghaboy135Turf24
paulfitz320
Cell Formulas
RangeFormula
I2:I22I2=LET(d, B2, Date1,INDEX($B$2:$B2,MATCH(D2&1,$D$2:$D2&$H$2:$H2,0)),h,H2, result,IFERROR(IF(h=1,"",IF(h=2,IF(d>Date1,4,IF(d<Date1,3,"")),"")),""),result)
 
Upvote 0
Thanks. Unfortunately the formula will not do what I need it to do. For example cell I2 should contain a 3. Also column D will contain many more rows with many groups of horses. When I paste it into the actual sheet with over 5000 rows, the formula does not adjust for the next horse and its group of runs.

Anyway thanks again, much appreciated.
 
Upvote 0
Then you gave incomplete requirements. The ONLY requirement you list above when a "1" is in Column H is:
COL H - If it contains a 1 for that horse leave adjacent cell in COL I blank

So please give all the information for your calculations for cells in column I. The forum cannot read minds.
 
Upvote 0
The ONLY requirement you list above when a "1" is in Column H is:
As far as I can see that is the only requirement when a "1" is in column H according to the expected results given in post 1.

Please add that your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

From your sample data it appears that the data for each horse is grouped together and the dates in column B are in ascending order for each horse. If that is always the case then does this do what you want?

23 10 30.xlsm
BDHI
1DateHorsehurdle debut ynAfter 1 Next Door
227/04/2021Adamantly Chosen23
327/11/2021Adamantly Chosen1 
48/01/2022Adamantly Chosen24
510/02/2022Adamantly Chosen24
618/03/2022Adamantly Chosen24
730/04/2022Adamantly Chosen24
828/07/2022Adamantly Chosen24
919/09/2022Adamantly Chosen24
1012/10/2022Adamantly Chosen24
114/12/2022Adamantly Chosen24
1226/12/2022Adamantly Chosen24
135/02/2023Adamantly Chosen24
1415/03/2023Adamantly Chosen24
159/04/2023Adamantly Chosen24
1628/04/2023Adamantly Chosen24
1719/08/2022Aghaboy1 
189/09/2022Aghaboy24
1918/09/2022Aghaboy24
204/12/2022Aghaboy24
2126/12/2022Aghaboy24
223/08/2023Aghaboy24
paulfitz320
Cell Formulas
RangeFormula
I2:I22I2=IF(H2=1,"",3+(COUNTIFS(D$2:D2,D2,H$2:H2,1)>0))
 
Upvote 0
Thank you, Peter.

Your formula is not far off.

To finish it....
The grouping variable is Col D (Horse)
Whenever a horse does not contain the number 1 for any of its runs in COL H, then a 4 needs to returned in COL I.
I've posted another example below...
The horse Acapella Bourgeois contains no number 1 in its COL H, so a 4 should be returned in all its rows in COL I
The horse Adamantly Chosen is correct as its COL I contains a 3 (as its proceeded by a 1 in COL H), COL I is blank as its adjacent to a 1 in COL H, COL I contains 4 for all runs for that horse after the date where it was awarded a 1 in COL H. Your correct all horses are sorted by date in ascending order.
I hope that's clear. I will put up my Excel version as requested.
Thanks again.

wpm hurdles won hurdles debut sp less then 9to2.xlsx
ABCDEFGHI
1CourseDateTimeHorseFin PosHurdle Runs BeforeRace Typehurdle debut ynwanted
2Sligo23/08/202320:10A Penny A Hundred10NHF23
3Limerick21/10/202314:05A Penny A Hundred10Hurdle1 
4Gowran Park17/02/201815:10Abbyssial47Hurdle23
5Cheltenham14/03/201814:50AbbyssialPU8Hurdle23
6Fairyhouse17/04/201817:50Abbyssial139Hurdle23
7Punchestown28/04/201817:35Abbyssial1910Hurdle23
8Punchestown31/12/202215:42Abi's Champ20NHF23
9Downpatrick17/06/202317:10Abi's Champ10NHF23
10Killarney21/07/202317:25Abi's Champ10NHF23
11Gowran Park29/09/202317:35Abi's Champ30NHF23
12Killarney15/05/202317:55Absurde10Hurdle1 
13Ascot20/06/202318:10Absurde21Turf24
14Galway01/08/202317:10Absurde61Hurdle24
15York26/08/202315:35Absurde12Turf24
16Fairyhouse14/01/201814:35Acapella BourgeoisPU6Chase23
17Cheltenham15/03/201917:30Acapella Bourgeois176Hurdle23
18Clonmel26/03/201916:20Acapella Bourgeois17Chase23
19Fairyhouse22/04/201917:00Acapella Bourgeois37Chase23
20Navan07/12/201913:05Acapella Bourgeois107Hurdle23
21Tramore01/01/202014:20Acapella Bourgeois28Chase23
22Gowran Park23/01/202015:00Acapella Bourgeois68Chase23
23Fairyhouse22/02/202016:02Acapella Bourgeois18Chase23
24Tramore01/01/202114:37Acapella Bourgeois28Chase23
25Gowran Park28/01/202115:25Acapella Bourgeois58Chase23
26Fairyhouse27/02/202114:52Acapella Bourgeois18Chase23
27Aintree10/04/202117:15Acapella Bourgeois138Chase23
28Tramore01/01/202214:20Acapella BourgeoisPU8Chase23
29Kilbeggan17/06/201918:00AccidentalPU3Hurdle23
30Punchestown27/04/202117:55Adamantly Chosen10NHF23
31Fairyhouse27/11/202113:01Adamantly Chosen20Hurdle1 
32Cork08/01/202213:03Adamantly Chosen21Hurdle24
33Thurles10/02/202214:55Adamantly Chosen12Hurdle24
34Cheltenham18/03/202217:30Adamantly Chosen113Hurdle24
35Punchestown30/04/202217:30Adamantly Chosen44Hurdle24
36Galway28/07/202217:05Adamantly Chosen135Hurdle24
37Listowel19/09/202217:05Adamantly Chosen16Chase24
38Punchestown12/10/202215:55Adamantly Chosen16Chase24
39Fairyhouse04/12/202213:55Adamantly Chosen56Chase24
40Limerick26/12/202214:40Adamantly Chosen26Chase24
41Leopardstown05/02/202313:40Adamantly Chosen26Chase24
42Cheltenham15/03/202314:10Adamantly Chosen76Chase24
43Fairyhouse09/04/202316:55Adamantly Chosen66Chase24
44Punchestown28/04/202316:15Adamantly ChosenPU6Chase24
wpm hurdles won hurdles debut s
Cell Formulas
RangeFormula
H2:H44H2=IF(AND(F2=0,G2="Hurdle"),1,2)
I2:I44I2=IF(H2=1,"",3+(COUNTIFS(D$2:D2,D2,H$2:H2,1)>0))
 
Upvote 0
Whenever a horse does not contain the number 1 for any of its runs in COL H, then a 4 needs to returned in COL I.
Well that possibility/condition was definitely not included in post 1 so it isn't surprising that the suggested formula did not account for it. ;)

Try this instead.

23 10 30.xlsm
DHI
1Horsehurdle debut ynwanted
2A Penny A Hundred23
3A Penny A Hundred1 
4Abbyssial24
5Abbyssial24
6Abbyssial24
7Abbyssial24
8Abi's Champ24
9Abi's Champ24
10Abi's Champ24
11Abi's Champ24
12Absurde1 
13Absurde24
14Absurde24
15Absurde24
16Acapella Bourgeois24
17Acapella Bourgeois24
18Acapella Bourgeois24
19Acapella Bourgeois24
20Acapella Bourgeois24
21Acapella Bourgeois24
22Acapella Bourgeois24
23Acapella Bourgeois24
24Acapella Bourgeois24
25Acapella Bourgeois24
26Acapella Bourgeois24
27Acapella Bourgeois24
28Acapella Bourgeois24
29Accidental24
30Adamantly Chosen23
31Adamantly Chosen1 
32Adamantly Chosen24
33Adamantly Chosen24
34Adamantly Chosen24
35Adamantly Chosen24
36Adamantly Chosen24
37Adamantly Chosen24
38Adamantly Chosen24
39Adamantly Chosen24
40Adamantly Chosen24
41Adamantly Chosen24
42Adamantly Chosen24
43Adamantly Chosen24
44Adamantly Chosen24
paulfitz320 (2)
Cell Formulas
RangeFormula
H2:H44H2=IF(AND(F2=0,G2="Hurdle"),1,2)
I2:I44I2=IF(H2=1,"",3+OR(COUNTIFS(D$2:D2,D2,H$2:H2,1)>0,COUNTIFS(D$2:D$44,D2,H$2:H$44,1)=0))
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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