Is their a simply faster Variation of this formula?

Mathman

Board Regular
Joined
Jan 28, 2017
Messages
152
Office Version
  1. 2016
Platform
  1. Windows


Hi


Any idea as to how this can re-written so it can be simpler and calculate faster?


=IF(COUNTIF(A$149,">0")+COUNTIF(A150,">0")=2,A$149/A150-1,0)+IF(COUNTIF(A$149,">0")+COUNTIF(A150,"<0")=2,(A$149/A150-1)*-1,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,">0")=2,A$149/A150-1,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,"<0")=2,A150/A$149-1,0)+IF(COUNTIF(A$149,"=0")+COUNTIF(A150,">0")=2,-100%,0)+IF(COUNTIF(A$149,"=0")+COUNTIF(A150,"<0")=2,100%,0)+IF(COUNTIF(A$149,">0")+COUNTIF(A150,"=0")=2,100%,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,"=0")=2,-100%,0)


Thanks!
MM
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I don't understand why you're using COUNTIF on a single cell here, makes no sense. If you want to see if a value in a single cell is > than some number, why not just write it as IF(A$149 > 0) ? Similarly, your first two tests could be simplified to SUM(A$149,A150) = 2 for both cells have to be >0 for the SUM to equal 2. I suspect there's a lot of this type of simplification that could occur within the formula which would probably speed its calculation.
 
Last edited:
Upvote 0
Why do you have COUNTIF around a single cell, you COUNTIF on a range not a single cell?

There's a shorter way than this too I'm sure

IF(AND(A149>0,A150>0),A149/A150-1,0)+
IF(AND(A149>0,A150<0),-(A149/A150-1),0)+
IF(AND(A149<0,A150>0),A149/A150-1,0)+
IF(AND(A149<0,A150<0),A150/A149-1,0)+
IF(AND(A149=0,A150>0),-1,0)+
IF(AND(A149=0,A150<0),1,0)+
IF(AND(A149>0,A150=0),1,0)+
IF(AND(A149<0,A150=0),-1,0)
 
Upvote 0
What happens if A149=0 AND A150=0 ?

That situaion hasn't been catered for.

There are two factors A149 and A150.
Each of these can have three different outcomes, less than zero, equal zero, or greater than zero.

That's 9 (3 * 3) possible outcomes.

You've only accounted for 8 of them.
 
Last edited:
Upvote 0
It's highly improbable to have the values equal zero. I will give your suggestion a try and see how it works out.


Thanks!
MM
 
Upvote 0
Well, using COUNTIF on a single cell is usually overkill. You can change:

=IF(COUNTIF(A$149,">0")+COUNTIF(A150,">0")=2,A$149/A150-1,0)

to

=IF(AND(A$149>0,A150>0),A$149/A150-1,0)

Next, your result is always some form of A$149/A150-1 (except for the <0, <0 part which is A150/A$149). Calculate that first, then worry about the sign. Something like:

=IFERROR(A$149/A150-1,1)*IF(SIGN(A$149)<>SIGN(A150),-1,1)

This formula does not match the results of your formula in all cases, so you'll need to tweak it, but I don't know what you're trying to calculate so I can't do much better. But it's much simpler, and you should be able to adapt it.


 
Upvote 0
I was thinking of constructing a table of 9 elements thus

1. A150/A149-1
2. -1
3. A149/A150-1
4. 1
5. 0 (A149=0 and A150=0)
6. -1
7. -(A149/A150-1)
8. -1
9. A149/A150-1

These are the 9 outcomes ranging from <0, <0 to >0, >0

Then use

(SIGN(A149)+2)*(SIGN(A150)+2)
as an index to that table using INDEX() and do an evaluate on the result
 
Last edited:
Upvote 0
It's difficult to see what you're trying to accomplish here. What matters here in terms of logic? Is it:
  • the pairwise combinations (e.g., 0,0)
  • the sum of the values =2,
  • both?

Also, are the values you're testing on limited to (-1, 0 , 1) or can they be any number?

Can you itemize the unique value_if_true and value_if_false arguments? I often find it easier to identify the possible outcomes and then identify the conditions that apply to them.
 
Upvote 0
Here are all the variations possible I am trying to capture. First number refers to cell A$149 and the second number refers to cell A150. Hope this helps!


1 2 1/2-1
2 1 2/1-1
1 -2 1/2-1*-1
-2 1 -2/1-1
-1 -2 -2/-1-1
-2 -1 -1/-2-1
 
Upvote 0
After spending too much time on this, I think Special-K99's formula from post 3 is best. That removes the unneeded COUNTIFs, but leaves the formula easy to read, especially with the line feeds.

Using his idea from post 7, and constructing the table (D148:F156) I constructed a shorted formula with CHOOSE. However, without the table, the formula is a bit obscure.

ABCDEF
146Based on post 1
147sign of A149sign of A150Result
148-80%-1-1A150/A149-1
1491-10-1
1505-80%-11A149/A150-1
1510-11
152-80%000
15301-1
1541-11-A149/A150
155101
15611A149/A150-1

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C148=IF(COUNTIF(A$149,">0")+COUNTIF(A150,">0")=2,A$149/A150-1,0)+IF(COUNTIF(A$149,">0")+COUNTIF(A150,"<0")=2,(A$149/A150-1)*-1,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,">0")=2,A$149/A150-1,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,"<0")=2,A150/A$149-1,0)+IF(COUNTIF(A$149,"=0")+COUNTIF(A150,">0")=2,-100%,0)+IF(COUNTIF(A$149,"=0")+COUNTIF(A150,"<0")=2,100%,0)+IF(COUNTIF(A$149,">0")+COUNTIF(A150,"=0")=2,100%,0)+IF(COUNTIF(A$149,"<0")+COUNTIF(A150,"=0")=2,-100%,0)
C150=IF(AND(A149>0,A150>0),A149/A150-1,0)+
IF(AND(A149>0,A150<0),-(A149/A150-1),0)+
IF(AND(A149<0,A150>0),A149/A150-1,0)+
IF(AND(A149<0,A150<0),A150/A149-1,0)+
IF(AND(A149=0,A150>0),-1,0)+
IF(AND(A149=0,A150<0),1,0)+
IF(AND(A149>0,A150=0),1,0)+
IF(AND(A149<0,A150=0),-1,0)
C152=CHOOSE((SIGN(A$149)+1)*3+(SIGN(A150)+2),A150/A149-1,-1,A149/A150-1,1,0,-1,1-A149/A150,1,A149/A150-1)

<tbody>
</tbody>

<tbody>
</tbody>


All 3 formulas return the same results, as far as I've tested. It still kind of nags me that there should be a cleaner, shorter formula, but I fear that it would require a bit more analysis of your model.

Good luck.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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