Excluding FALSE elements from arrays...

mrzippy

New Member
Joined
Apr 15, 2015
Messages
7
Hi there,


When applying a built-in Excel function (such as AVERAGE) to an array, all FALSE elements are automatically excluded. For example, the formula:


=AVERAGE({2,4,FALSE})


is treated as being equivalent to


=AVERAGE({2,4})


and so both formulae produce the value 3, as expected.


However, the following formula:


=AVERAGE({2,4,FALSE}-{1,1,FALSE})


produces the value 1.33333, which (as far as I'm concerned) is unexpected. I would have expected the above formula to produce the value 2, since the FALSE element in the resulting internal array *should* be ignored, and the formula should be equivalent to


=AVERAGE({2,4}-{1,1})


It would appear that, upon performing the internal subtraction, Excel is replacing the FALSE element with the number zero. So if I'm understanding this correctly, Excel is essentially carrying out the following simplification:


=AVERAGE({2,4,FALSE}-{1,1,FALSE})
=AVERAGE({1,3,0})
=1.3333333


whereas what I really want is


=AVERAGE({2,4,FALSE}-{1,1,FALSE})
=AVERAGE({1,3,FALSE})
=AVERAGE({1,3})
=2


Is there any way of forcing Excel to exclude FALSE elements from arrays? I would like to apply various built-in functions (i.e. not just AVERAGE) to arrays containing FALSE elements, so it would be wonderful if there was some way of achieving this!


Many thanks,


-Matt
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Excel coerces Booleans to 1 and 0 when they are operands in an arithmetic expression. In your second example, AVERAGE never sees the FALSE values; it sees the results of the arithmetic.
 
Upvote 0
Code:
=average(if(({2,4,false}-{1,1,false})<>0,{2,4,false}-{1,1,false}))
 
Upvote 0
What if 0 is the result of the subtraction of two numbers?
 
Upvote 0
What if 0 is the result of the subtraction of two numbers?
Good point... if two corresponding elements, when subtracted, produce the number zero, then (using lrobbo314's formula) that element is incorrectly excluded from the AVERAGE calculation.

As you said in your first response, the problem is that FALSE elements are coerced to the number zero when the subtraction is performed. If only there was some way of stripping the FALSE elements from the original arrays prior to the subtraction. I don't suppose Excel offers such a function?
 
Upvote 0
You could always go to something like

(SUM({4,2,FALSE})-SUM({1,1,False}))/COUNT({4,2,FALSE})

My question is what do you want to do if the Falses occur in different places in the array


What would you want returned for AVERAGE({4, 2, FALSE} - {1, FALSE, 1})
 
Upvote 0
Maybe

=AVERAGE(IF(ISNUMBER({2,4,FALSE}) * ISNUMBER({2,1,FALSE}), {2,4,FALSE} - {2,1,FALSE}))
 
Upvote 0
I'm coming to the opinion that these work-arounds are not worth it.
Helper columns would probably be faster than all these ISNUMBER/IF array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

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