02-09-2019 05:19 AM
I'm not getting an error, I'm just not getting many results. I suspect its because of my greater than or less than zero requirements. The cells that contain the requirements are percentages so 1.0 is greater than zero and 0.1 is less than zero, correct? This formula worked perfectly before I added "OR" & "greater than or less than zero" requirements.
OLD formula that works perfectly:
=IF(AND($AB30<$AC30, $AD30<$AE30, $AF30<$AG30, $AH30<$AI30, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30),$Q30/$P30,"")
NEW formula that works but pulls little data:
=IF(AND( $AB30<$AC30,$D21>0, $AD30<$AE30,$F21>0, $AF30<$AG30,$H21>0, $AH30<$AI30,$J21>0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $D21<0, $AD30<$AE30,$F21>0, $AF30<$AG30,$H21>0, $AH30<$AI30,$J21>0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $F21<0, $AF30<$AG30,$H21>0, $AH30<$AI30,$J21>0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $AD30<$AE30,$F21>0, $H21<0, $AH30<$AI30,$J21>0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $AD30<$AE30,$F21>0, $AF30<$AG30,$H21>0, $J21<0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $F21<0, $AF30<$AG30,$H21>0, $J21<0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30,
OR( $F21<0, $H21<0, $AH30<$AI30,$J21>0, $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30
))))))),$Q30/$P30,"")
02-09-2019 05:33 AM
02-09-2019 05:42 AM
Hi Greg,
Depend on what is the logic behind. In your formula OR conditions are nested under AND conditions, like
=IF(AND(cond1,cond2,OR(cond3,cond4)), result, "")
Is that what you'd like to achieve? Or
=IF( OR(AND(cond1, cond2), AND(cond3, cond4)), result, "")
02-09-2019 05:54 AM
If you'd like to remove $AB30<$AC30 if D21 is negative you may use
($AB30<$AC30)*($D$21>=0)
it gives FALSE if D21 is negative and result of AB30, AC30 comparison otherwise.
02-09-2019 06:11 AM
02-09-2019 06:24 AM
02-09-2019 06:48 AM
SolutionSorry, it excludes it if OR condition. To exclude from AND it could be like
=IF(AND( IF($D21>0,$AB30<$AC30,1), IF($F21>0,$AD30<$AE30,1), IF($H21>0,$AF30<$AG30,1), IF($J21>0,$AH30<$AI30,1), $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30), $Q30/$P30,"")
If D21 is negative first IF returns TRUE independently of what is in AB30 and AC30 and that doesn't affect other conditions under AND. Please see attached.
02-10-2019 03:30 PM
This worked perfectly. Thank you!!!!!
02-10-2019 05:53 PM
02-10-2019 05:59 PM
Follow up: Looking at the results I think you solved the problem but looking at the formula I cant see how logically it is solved. So I'm questioning my own eyes. Please confirm.
02-11-2019 12:25 AM
Hi Greg,
Sorry, I missed. Do you need the entire formula returns FALSE if ANY of D21, F21, H21 is negative? Or only all combinations of $AB30<$AC30, $AD30<$AE30, $AF30<$AG30 are ignored if any of D21, F21, H21 is negative?
Current formula excludes $AB30<$AC30 if D21 is negative; $AD30<$AE30 if F21 negative and the same for the third combination.
How the formula works you may check if stay on the cell with formula, on ribbon click Formulas->Evaluate formula, it shows step by step all calculations.
02-11-2019 07:18 AM
D21, F21, H21 should remove only individual "$AB30<$AC30, $AD30<$AE30, $AF30<$AG30". However if all "D21, F21, H21" are negative, the whole formula should be false.
02-11-2019 02:28 PM
Greg, that could be like
=IF(AND( IF($D21>0,$AB30<$AC30,1), IF($F21>0,$AD30<$AE30,1), IF($H21>0,$AF30<$AG30,1), IF($J21>0,$AH30<$AI30,1), $AJ30<$AK30, $AL30<$AM30, $AN30<$AO30, $AP30<$AQ30, (($D21>0)+($F21>0)+($H21>0)) ), $Q30/$P30,"")
02-13-2019 02:24 AM
Hi Thank you for your assistance. I could not use your code here because It produced an odd result. Too much too explain Just now. Id rather spend the time explaining more carefully what I'm aiming for:
First please note the change I made in your code. This below is our template, Not the original from the beginning of this conversation.
=IF(AND(
IF($D21>0,$AB30<$AC30,1),
IF($F21>0,$AD30<$AE30,1),
IF($H21>0,$AF30<$AG30,1),
$AH30<$AI30,
$AJ30<$AK30,
$AL30<$AM30,
$AN30<$AO30,
$AP30<$AQ30,
(($D21>0)+($F21>0)+($H21>0))
), $Q30/$P30,"")
(The change is the elimination of J21 requirement)
So here is what I'm shooting for:
As long as d21 or f21 or h21 are greater than zero, then q30/p30 computes.
The key word is "OR" here.
However if d21 and f21 and h21 are negative, then q30/p30 should not compute.
Hopefully this clarifies. Thanks
02-13-2019 07:13 AM
Hi Greg,
What formula do
(($D21>0)+($F21>0)+($H21>0)) is the equivalent of OR(($D21>0),($F21>0),($H21>0))
they return the same result. IF all of above cells are negative that OR returns FALSE. Entire AND(...,FALSE) also returns FALSE and IF gives empty text as result.
If any of above is positive, when OR returns TRUE, AND(...,TRUE) returns what previous conditions give and entire IF gives Q30/P30 if TRUE, otherwise empty string.
As for the latest - if, as you say, in case of any of D21, F21, H21 is positive the formula shall always return Q30/P30 it's not clear why do we need other conditions under AND. Now we check if any of above is positive and after that apply other conditions.
02-14-2019 03:24 AM
Sergei, I figured out the problem. I have not been explaining my manual process correctly.
If I see that $D21>0 I manually add $AB30<$AC30, to $AH30<$AI30, $AJ30<$AK30, $AL30<$AM30,$AN30<$AO30, $AP30<$AQ30), $Q30/$P30,"")
If I see that $F21>0 I manually add $AD30<$AE30, to $AH30<$AI30, $AJ30<$AK30, $AL30<$AM30,$AN30<$AO30, $AP30<$AQ30), $Q30/$P30,"")
If I see that $H21>0 I manually add $AF30<$AG30, to $AH30<$AI30, $AJ30<$AK30, $AL30<$AM30,$AN30<$AO30, $AP30<$AQ30), $Q30/$P30,"")
I do the opposite If d21 or F21 OR h21 become less than zero by manually removing those added codes.
However if at any time all 3 become negative the result of Q30/P30 will not compute because at least one of the 3 D21,F21,H21 are in the code preventing Q30/P30 from being true.
Can you make a code out of this manual process?
02-14-2019 01:57 PM
Hi Greg,
Could you please give me an example when formula doesn't work, perhaps I don't understand something. From my point of view it works as you described.
02-14-2019 03:30 PM
In my manual code a macro sorts the results of $Q30/$P30, correctly leaving all blank fields at the bottom of the sort. In your automated code the blanks are randomly anywhere in the sort.
My manual code:
=IF(AND(
$AB30<$AC30,
$AD30<$AE30,
$AF30<$AG30,
$AH30<$AI30,
$AJ30<$AK30,
$AL30<$AM30,
$AN30<$AO30,
$AP30<$AQ30),
$Q30/$P30,"")
02-14-2019 04:34 PM
We didn't speak about the sorting, we spoke about the formula for the concrete set of cells. If you apply that formula to the next row, i.e. to check $Q31/$P31, criteria also will be like $AB31<$AC31 and on the top we check $L22, etc (not $L21). Correct?
02-14-2019 04:47 PM
everything you said is correct except L22. The D21, F21 and H21 are static positions