Heyy
I'm looking for formula to deduct 2 from the first non-zero cell and from the last non-zero value cell only.
So far I use IF formula (with reference to the table below):
=IF(B1=(INDEX($B1:$F1,MATCH(TRUE,INDEX($B1:$F1<>0,),0))), (B1-2), IF(B1=(LOOKUP(2,1/($B1:$F1<>0),$B1:$F1)), (B1-2), B1))
Problem 1
The problem here is that if there are similar number for the first non-zero (INDEX($B2:$F2,MATCH(TRUE,INDEX($B2:$F2<>0,),0)) or the last non-zero (LOOKUP(2,1/($B2:$F2<>0),$B2:$F2) within the list, so the formula will result in minus 2 for the duplicate numbers as well instead of just the first/last non-zero value.
Example:
Problem 2
The second issue is that we don't want -1 result. Therefore, if the last/first non-zero value is 1 (which will result in -1) we need it to minus 1 only and bring the other 1 (from the original minus 2) to the second first/last non-zero value.
Example:
Any ideas how to solve these problems? Or at least one of them?
Please and thank you!
I'm looking for formula to deduct 2 from the first non-zero cell and from the last non-zero value cell only.
So far I use IF formula (with reference to the table below):
=IF(B1=(INDEX($B1:$F1,MATCH(TRUE,INDEX($B1:$F1<>0,),0))), (B1-2), IF(B1=(LOOKUP(2,1/($B1:$F1<>0),$B1:$F1)), (B1-2), B1))
Data | 0 | 2 | 4 | 4 | 1 |
Result | 0 | 0 | 4 | 4 | -1 |
Problem 1
The problem here is that if there are similar number for the first non-zero (INDEX($B2:$F2,MATCH(TRUE,INDEX($B2:$F2<>0,),0)) or the last non-zero (LOOKUP(2,1/($B2:$F2<>0),$B2:$F2) within the list, so the formula will result in minus 2 for the duplicate numbers as well instead of just the first/last non-zero value.
Example:
Data | 0 | 2 | 4 | 1 | 1 |
Result | 0 | 0 | 4 | -1 | -1 |
Problem 2
The second issue is that we don't want -1 result. Therefore, if the last/first non-zero value is 1 (which will result in -1) we need it to minus 1 only and bring the other 1 (from the original minus 2) to the second first/last non-zero value.
Example:
Data | 1 | 1 | 0 | 4 | 5 |
Result | 0 | 0 | 0 | 4 | 3 |
Any ideas how to solve these problems? Or at least one of them?
Please and thank you!