haruspication
New Member
- Joined
- Jan 19, 2012
- Messages
- 17
I need to include a function in my C2 cell formula that will skip days with non-zero values and then list the next non-zero day (the day is also listed N times based on Col B value).
[TABLE="class: grid, width: 300, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Mon
[/TD]
[TD]2
[/TD]
[TD]Mon
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Tues
[/TD]
[TD]1
[/TD]
[TD]Mon
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Wed
[/TD]
[TD]0
[/TD]
[TD]Tues
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]Thurs
[/TD]
[TD]0
[/TD]
[TD]Fri
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]Fri
[/TD]
[TD]1
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Cell C1: Formula finds the first day (Col A) with a non-zero value (Col B) and lists it in C1.
Cell C2: Lists each day (Col A) N times based on the day's corresponding value in Col B.
=IFERROR(IF(COUNTIF($G$2:G2,G2)=INDEX(E:E,MATCH(G2,A:A,0)),IF(AND(INDEX(A:A,MATCH(G2,A:A,0)+1)<>0,INDEX(E:E,MATCH(G2,A:A,0)+1)<>0), INDEX(A:A,MATCH(G2,A:A,0)+1), IF(INDEX(E:E,MATCH(G2,A:A,0)+1)=0,INDEX(A:A,MATCH(TRUE,E:E<>0,0)), "-")),G2),"-")
The current function to skip zeros is in RED and it's wrong because it lists "Mon" repeatedly because it only finds the first day without a zero, rather than the first day without a zero based on the previous value (eg., if the last non-zero day listed in Col C is Tues, then the formula would skip Wed and Thurs and then list Fri)
[TABLE="class: grid, width: 300, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Mon
[/TD]
[TD]2
[/TD]
[TD]Mon
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Tues
[/TD]
[TD]1
[/TD]
[TD]Mon
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Wed
[/TD]
[TD]0
[/TD]
[TD]Tues
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]Thurs
[/TD]
[TD]0
[/TD]
[TD]Fri
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]Fri
[/TD]
[TD]1
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Cell C1: Formula finds the first day (Col A) with a non-zero value (Col B) and lists it in C1.
Cell C2: Lists each day (Col A) N times based on the day's corresponding value in Col B.
=IFERROR(IF(COUNTIF($G$2:G2,G2)=INDEX(E:E,MATCH(G2,A:A,0)),IF(AND(INDEX(A:A,MATCH(G2,A:A,0)+1)<>0,INDEX(E:E,MATCH(G2,A:A,0)+1)<>0), INDEX(A:A,MATCH(G2,A:A,0)+1), IF(INDEX(E:E,MATCH(G2,A:A,0)+1)=0,INDEX(A:A,MATCH(TRUE,E:E<>0,0)), "-")),G2),"-")
The current function to skip zeros is in RED and it's wrong because it lists "Mon" repeatedly because it only finds the first day without a zero, rather than the first day without a zero based on the previous value (eg., if the last non-zero day listed in Col C is Tues, then the formula would skip Wed and Thurs and then list Fri)