Select # of Months Based on Yes/No in Table

nirvehex

Well-known Member
Joined
Jul 27, 2011
Messages
503
Office Version
  1. 365
Platform
  1. Windows
Hi All,

This is a tough one that I've been doing manually:

I have a table that looks like this:
Implementation Months# of Implementation MonthsJun - 20Jul - 20Aug - 20Sep - 20Oct - 20Nov - 20Dec - 20Jan - 21Feb - 21Mar - 21Apr - 21May - 21
Oct-May8YesYesYesYesYesYes
Apr-Oct7YesYesYesYesYesYes
Sep-May9YesYesYesYesYesYesYesYes
Nov-Feb / May-Jun6YesYesYesYesYesYes
Aug-Apr9YesYesYesYesYesYes
Dec-Jul8YesYesYesYesYesYesYesYes
Jan-May5YesYesYesYes
Sep-Jan / Apr-May7YesYesYesYesYesYes
Nov-Apr6YesYesYesYesYes
Dec-Jun7YesYesYesYesYesYesYes

I'm trying to fill in "Implementation Months" and "# of Implementation Months" based on the following logic:

(1) for "Yes" streaks longer than or equal to 2 months and
(2) where "Yes" appears continuously with at most 1 blank month in between; if multiple streaks break out streaks with a " / " like "Nov-Feb / May-Jun"
(3) generate a formula for "Implementation Months" column and "# of Implementation Months" column

I have filled in the correct answers for the above table in the first two columns. Can anyone please help me with figuring out a formula so I don't have to do this manually? I am at such a loss here. Thank you!
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Quite tough indeed! This might be better suited to VBA actually, but I managed to get it to work. Try:

Book1
ABCDEFGHIJKLMNOPQRSTU
1Implementation Months# of Implementation Months20-Jun20-Jul20-Aug20-Sep20-Oct20-Nov20-Dec21-Jan21-Feb21-Mar21-Apr21-May
2Oct-May8YesYesYesYesYesYes512
3Apr-Oct7YesYesYesYesYesYes115
4Sep-May9YesYesYesYesYesYesYesYes412
5Nov-Feb / May-Jun6YesYesYesYesYesYes61291
6Aug-Apr9YesYesYesYesYesYes311
7Dec-Jul8YesYesYesYesYesYesYesYes72
8Jan-May5YesYesYesYes812
9Sep-Jan / Apr-May7YesYesYesYesYesYes411812
10Nov-Apr6YesYesYesYesYes611
11Dec-Jun7YesYesYesYesYesYesYes4741
Sheet1
Cell Formulas
RangeFormula
A2:A11A2=IFERROR(TEXTJOIN(" / ",,IF(P2#<>S2#,TEXT(INDEX(C$1:N$1,P2#),"mmm")&"-"&TEXT(INDEX(C$1:N$1,S2#),"mmm"),"")),TEXT(C$1,"mmm")&"-"&TEXT(N$1,"mmm"))
B2:B11B2=IFERROR(SUM(IF(S2#=P2#,0,IF(S2#>P2#,S2#-P2#,S2#+12-P2#)+1)),12)
P2:P4,P6:P8,P10,P11:Q11,P9:Q9,P5:Q5P2=FILTER(COLUMN(C2:N2)-COLUMN(C2)+1,IF(INDEX(C2:N2,MOD(COLUMN(C2:N2)-COLUMN(C2)-2,12)+1)="","N","Y")&IF(INDEX(C2:N2,MOD(COLUMN(C2:N2)-COLUMN(C2)-1,12)+1)="","N","Y")&IF(C2:N2="","N","Y")="NNY")
S2:S4,S6:S8,S10,S11:T11,S9:T9,S5:T5S2=MOD((FIND("YNN.",TEXTJOIN(".",,IF(INDEX(C2:N2,MOD(SEQUENCE(,23)-1,12)+1)="","N","Y")&IF(INDEX(C2:N2,MOD(SEQUENCE(,23,2)-1,12)+1)="","N","Y")&IF(INDEX(C2:N2,MOD(SEQUENCE(,23,3)-1,12)+1)="","N","Y")),(P2#-1)*4)-1)/4,12)+1


I needed some helper columns. And I'm not quite sure why the P2 formula didn't show up as a Dynamic Array formula, since it uses FILTER, and S2 uses SEQUENCE.
 
Upvote 0
Solution
Much shorter versions of the P and S formulas:

Book1
ABCDEFGHIJKLMNOPQRST
1Implementation Months# of Implementation Months20-Jun20-Jul20-Aug20-Sep20-Oct20-Nov20-Dec21-Jan21-Feb21-Mar21-Apr21-May
2Oct-May8YesYesYesYesYesYes512
3Apr-Oct7YesYesYesYesYesYes115
4Sep-May9YesYesYesYesYesYesYesYes412
5Nov-Feb / May-Jun6YesYesYesYesYesYes61291
6Aug-Apr9YesYesYesYesYesYes311
7Dec-Jul8YesYesYesYesYesYesYesYes72
8Jan-May5YesYesYesYes812
9Sep-Jan / Apr-May7YesYesYesYesYesYes411812
10Nov-Apr6YesYesYesYesYes611
11Dec-Jun7YesYesYesYesYesYesYes4741
Sheet1
Cell Formulas
RangeFormula
A2:A11A2=IFERROR(TEXTJOIN(" / ",,IF(P2#<>S2#,TEXT(INDEX(C$1:N$1,P2#),"mmm")&"-"&TEXT(INDEX(C$1:N$1,S2#),"mmm"),"")),TEXT(C$1,"mmm")&"-"&TEXT(N$1,"mmm"))
B2:B11B2=IFERROR(SUM(IF(S2#=P2#,0,IF(S2#>P2#,S2#-P2#,S2#+12-P2#)+1)),12)
P2:P4,P6:P8,P10,P11:Q11,P9:Q9,P5:Q5P2=FILTER(SEQUENCE(,12),MID(CONCAT(IF(M2:N2="","N","Y"),IF(C2:N2="","N","Y")),SEQUENCE(,12),3)="NNY")
S2:S4,S6:S8,S10,S11:T11,S9:T9,S5:T5S2=MOD(FIND("YNN",CONCAT(IF(C2:N2="","N","Y"),IF(C2:N2="","N","Y")),P2#)-1,12)+1
 
Upvote 0
And a shorter A2 formula:

Excel Formula:
=TEXTJOIN(" / ",,IF(P2#<>S2#,TEXT(INDEX(C$1:N$1,IFERROR(P2#,1)),"mmm")&"-"&TEXT(INDEX(C$1:N$1,IFERROR(S2#,12)),"mmm"),""))

Edit: Oops! Better stick with the original. This fails with a 12-month stretch.
 
Last edited:
Upvote 0
Eric W - Thank you so much! The first example you constructed worked perfectly!! Truly, thank you, this is going to save me hours and time is so valuable! Really, really appreciate it!
 
Upvote 0
Glad it works for you! That was interesting to figure out. If the original formulas are working for you, by all means keep using them. But the P2 and S2 formulas from post 3 are a lot shorter and easier to understand.

Anyway, thanks for the feedback! ?
 
Upvote 0

Forum statistics

Threads
1,214,837
Messages
6,121,883
Members
449,057
Latest member
Moo4247

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