[SOLVED] Using OR statement in FormulaArray

hoffey

New Member
Joined
Jun 25, 2009
Messages
48
I seem to be stuck trying to use multiple variables in an array statement.

Code:
=SUM(IF(Hours!$A$2:$A$13189=HR!$A5,IF(OR(Hours!$B$2:$B$13189="ENG",Hours!$B$2:$B$13189="SNRENG"),Hours!$D$2:$D$13189,),))

Right now it sums everything if the first expression passes, so if the Hours column A matches HR!$A5 then it will sum all that match, disregarding the OR statement and additional matches.

Note I'm trying to use an OR statement because some of the other expressions I am trying to do are too long (above 255 char). Any advice on how to get this to work? I want to check Column A on HR sheet against A5, and then see if the B column makes additional matches to only sum up those.


EDIT: This formula below works, but once I start adding more 'OR' statements it becomes too long and reaches the char limit:

Code:
=SUM(IF(Hours!$A$2:$A$13189=HR!$A5,IF(Hours!$B$2:$B$13189="ENG",Hours!$D$2:$D$13189,),),IF(Hours!$A$2:$A$13189=HR!$A5,IF(Hours!$B$2:$B$13189="SNRENG",Hours!$D$2:$D$13189,),))
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Re: Using OR statement in FormulaArray

Try using a SUMPRODUCT - you can emulate OR by adding conditions together inside a double-unary operator:

=SUMPRODUCT(--(Hours!$A$2:$A$13189=HR!$A5),--((Hours!$B$2:$B$13189="ENG")+(Hours!$B$2:$B$13189="SNRENG")),Hours!$D$2:$D$13189)
 
Upvote 0
Re: Using OR statement in FormulaArray

Try using a SUMPRODUCT - you can emulate OR by adding conditions together inside a double-unary operator:

=SUMPRODUCT(--(Hours!$A$2:$A$13189=HR!$A5),--((Hours!$B$2:$B$13189="ENG")+(Hours!$B$2:$B$13189="SNRENG")),Hours!$D$2:$D$13189)

So SUMPRODUCT is not even an array? This would seemingly speed things up quite a bit. Any limitations or quirks I should know about? Really appreciate your help MrKowz...
 
Upvote 0
Re: Using OR statement in FormulaArray

Actually, SUMPRODUCT can seem a bit misleading. It is not entered as an array (CTRL+SHIFT+ENTER), but it inheritantly calculates as an array - so it is no faster than using an array formula (in fact, it is one of the slowest functions).

The reason why is because SUMPRODUCT actually performs an array operation.

However, despite it being a slow function, it is extremely handy and its pros by far outweigh the cons of its speed.

xlDynamic has a really great writeup and explanation of SUMPRODUCT here: http://www.xldynamic.com/source/xld.SUMPRODUCT.html
 
Upvote 0
May the new year bring you many exciting opportunities! Thanks again MrKowz, on my way to soak up some new knowledge on SUMPRODUCT.

;)
 
Upvote 0
Hi

Just a remark: You can also add the 2 conditions without the double unary operator. Since you are performing an arithmetic operation the booleans will be automatically converted to number.
 
Upvote 0
Hi

Just a remark: You can also add the 2 conditions without the double unary operator. Since you are performing an arithmetic operation the booleans will be automatically converted to number.

Hmm - I hadn't thought about this! Guess that I've relied on using the double unary so much that I forgot that little bit. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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