Forum Discussion
IF / Countif / Sumif - Formula help please
Example data and formula
=IF(AND($C12+1<=$C$2,IF($B13="",$C12+1)),IF(AND(C12=0,C11=0),C10+1),C12+1)
util 1 | util 2 | ||
20 | 26 | ||
READ DATE | HOLIDAY/WEEKEND | CYCLE | |
Sunday, January 01, 2017 | YES | ||
Monday, January 02, 2017 | YES | ||
Tuesday, January 03, 2017 | 1 | 1 | |
Wednesday, January 04, 2017 | 2 | 2 | |
Thursday, January 05, 2017 | 3 | 3 | |
Friday, January 06, 2017 | 4 | 4 | |
Saturday, January 07, 2017 | YES | 0 | 0 |
Sunday, January 08, 2017 | YES | 0 | 0 |
Monday, January 09, 2017 | 5 | 5 | |
Tuesday, January 10, 2017 | FALSE | 6 | |
Wednesday, January 11, 2017 | FALSE | 7 | |
Thursday, January 12, 2017 | FALSE | 8 | |
Friday, January 13, 2017 | FALSE | 9 | |
Saturday, January 14, 2017 | YES | 1 | 0 |
Sunday, January 15, 2017 | YES | 2 | 0 |
Monday, January 16, 2017 | FALSE | 10 | |
Tuesday, January 17, 2017 | FALSE | 11 | |
Wednesday, January 18, 2017 | FALSE | 12 |
Further to this...on my sample data below. The column with "Util 2 (26)" header example is how I'm trying to get column "Util 1 (20)" to look like. Note how the count of dates continually increment up except for weekends and holidays until it gets to top number where I want it to start over.
Thanks
- SergeiBaklanApr 22, 2017Diamond Contributor
Hi Chris,
In attached file is the prototype, results looks like
Instead of 26 you may put any number greater than 3 (number of rows above your data).
Calculations are added into the column F in parallel to your data where i added one more YES in yellow. Here is an assumption - you have to have the size of your cycle (26) somewhere in first rows of the column F, otherwise the logic of the formula is to be changed.
To generate the counter i used
=ROUND(MOD(<prev value>+0.7,26),0)
0.7 here is any one between 0.5 and 1 to round the result to next integer, you may use ROUNDUP as well.
To find the previous value for the counter we check for the current cell
OFFSET(F4,-1,0)
If it's not zero we take that value, if zero we find the latest non-zero value in the upper region with max 26 height size, or reduce the size if the current row is less than 26 to avoid the error generation. This part of the formula finds in reverse order the position of such value in above region
INDEX(MATCH(2,(--1/OFFSET(F4,-MIN(ROW()-1,$F$2),0,MIN(ROW()-1,$F$2))<>0))
After that we offset on this position and pickup the value of the previous counter
OFFSET(F4, -MIN(ROW(),$F$2)-(ROW()>$F$2)+INDEX(MATCH(2,(--1/OFFSET(F4,-MIN(ROW()-1,$F$2),0,MIN(ROW()-1,$F$2))<>0)),) ,0)
MIN gives the size of the region depends on current row position.
The correction
-(ROW()>$F$2)
is to add one more position when row number begins bigger than counter size. Perhaps could be done another way, but i didn't dig.
Entire formula for F4 is
=IF(B4="YES", 0, ROUND(MOD( IF(OFFSET(F4,-1,0)=0, OFFSET(F4, -MIN(ROW(),$F$2)-(ROW()>$F$2)+INDEX(MATCH(2,--(1/OFFSET(F4,-MIN(ROW()-1,$F$2),0,MIN(ROW()-1,$F$2))<>0)),),0), OFFSET(F4,-1,0) )+0.7, $F$2 ),0 ) )
copy it down to another cells. And finally apply custom format to them
0;;;@,
which shows zeroes as empty cells and the rest as integers.
- SergeiBaklanApr 22, 2017Diamond Contributor
And here i slightly modified relative/absolute refrences for column B and F2 if you copy/paste the F column to generate few cycles:
- Chris CookApr 22, 2017Copper Contributor
Wow. You were a huge help. It looks to be exactly what I needed help with. I'll review but it looks great at first glace. I can't thank you enough - this is great.
Chris