Ignore blank parameters in Excel array formula - arrays

I'm using an array formula to return sums and counts on a large data set.
The array formula can have up to 3 arguments but the formula needs to accommodate when any or all of the arguments are <blank>, WITHOUT using VBA.
For example
A1 = "Australia"
B1 = "Finance"
C1 = "Female"
D1 contains the formula
D1 = {count(if((region=A1)*(sector=B1)*(gender=C1),population))}
Sometimes one of the criteria will be blank
A1 = "Australia"
B1 = <blank>
C1 = "Male"
In this case I'd like the formula to return the equivalent of:
D1 = {count(if((region=A1)*(gender=C1),population))}
In the extreme case A1, B1 and C1 could be all blank in which case the formula in D1 should return the equivalent of Count(population)
Is there a way to create an array formula that accounts for these possibilities? I originally tried to create a dynamic argument string
E1 = "(region=A1)*(sector=B1)*(gender=C1)"
and then use the string as the argument within the array formula
D1 = {count(if(E1,population))}
but I could find a way to get this to work.
I've tried a number of solutions, but there is always a key element missing. By using isblank I can determine if the cell is blank, but in order for this to be useful I'd need to turn this returned value into an array of boolean values of length count(population).
Any and all ideas are greatly appreciated.
Thanks.

Have you tried Nz() ? Encapsulate your current code with that and give it a try. I've had issues with blanks/nulls here and there myself.
Another option could be the IIF() statement. But that might not do what you want it to. Here are reference links:
Nz: http://www.techonthenet.com/access/functions/advanced/nz.php
IIF: http://www.techonthenet.com/access/functions/advanced/iif.php

You don't need VBA and you also don't even need an array formula. You can use SUMPRODUCT() with wildcards.
Say we have:
In A2 enter:
=IF(A1="","*",A1)
and copy across. This will display either an asterisk or the value above.
Then use:
=SUMPRODUCT(ISNUMBER(SEARCH(A2,G1:G10,1))*ISNUMBER(SEARCH(B2,H1:H10,1))*ISNUMBER(SEARCH(C2,I1:I10,1)))
This is a way to get SUMPRODUCT() to accept the asterisk as a wildcard:

Related

#VALUES! while using IF and OR together

I have the File as following format
Name Number Position
A 1
B 2
C 3
D 4
Now on position A3 , I applied =IF(B2=1,"Goal Keeper",OR(IF(B2=2,"Defender",OR(IF(B2=3,"MidField","Striker"))))) But it giving me an error #value!
Looked up at google, and my formula is correct.
What i basically want it
1- Goalkeeper 2-Defender 3-Midfield 4-Striker
Yes the other way is to to just filter the number and copy paste the text
But I want to do it using formula and want to know where did I go wrong.
Your immediate problem lies with the expression (for example):
OR(IF(B2=3,"MidField","Striker"))
| \__/ \________/ \_______/ |
| bool string string |
\____________________________/
string
The OR function expects a series of boolean values (true or false) and you're giving it a string value from the inner IF.
You don't actually need the or bits in this specific case, the if is a full if-else. So you can just use:
=IF(B1=1,"Goal Keeper",IF(B2=2,"Defender",IF(B2=3,"MidField","Striker")))
This means that B1=1 will result in "Goal Keeper", otherwise it will evaluate IF(B2=2,"Defender",IF(B2=3,"MidField","Striker")).
Then that means that, if B2=2, it will result in "Defender", otherwise it will evaluate IF(B2=3,"MidField","Striker").
Finally, that means the B2=3 will result in "MidField", anything else will give "Striker".
The only situation I can envisage when OR would come in handy here would be when two different numbers were to generate the same string. Let's say both 1 and 4 should give "Goalie", you could use:
=IF(OR(B1=1,B1=4),"Goalie",IF(B2=2,"Defender","MidField"))
Keep in mind that a more general solution would be better implemented with the Excel lookup functions, ones that would search a table (on the spreadsheet somewhere) which mapped the integers to strings. Then, if the mapping needed to change, you would just update the table rather than going back and changing the formula in every single row.
If you are actually tasked with solving the problem by using the IF and OR function within the same equation, this is the only way I can see how:
=IF(OR(B1=1, B1 = 2, B1 = 3, B1 = 4),IF(B1 = 1, "Goal Keeper", IF(B1 = 2,"Defender",IF(B1 = 3,"MidField","Striker")))
If B1 does not equal 1-4, the OR function will return FALSE and completely bypass all of the nested IF statements.

Why is the MATCH function not working how anticipated in Excel with array formulas? (example attached)

File Located Here (using Google Drive)
Explanation and background: I have a list of animals and their color in column G (animal) and H (color). I have a list of the unique colors in column A, and a list of unique animals in column D. In column B, next to the list of unique colors, I need to know of all the animals, which animal has that color most often (raw number, not proportion.) I cannot use any additional helper cells.
I have established the max by animal for each color with the formula {=MAX(COUNTIFS(H:H,A2,G:G,$D$2:$D$20))} with the result being 7, but that's as far as I can get. I can set the COUNTIFS statement to the MAX statement like so: COUNTIFS(H:H,A2,G:G,E1:E19)=MAX(COUNTIFS(H:H,A2,G:G,E1:E19)) which can be used as a TRUE/FALSE array in an array formula. Finally I try to use MATCH with the previous formula as my array, and look for a TRUE value to attempt to retrieve the position of the only TRUE value in the array, but it seems to not be able to find it and instead gives me 19, which is the length of the entire array.
When I step through the formula, here's the step right before resulting in 19:
step before final result
Why does this MATCH not work?
put this in B2 :
=CHOOSE(IF(MAX(COUNTIFS(G:G,$E$1,H:H,A2),COUNTIFS(G:G,$E$2,H:H,A2),COUNTIFS(G:G,$E$3,H:H,A2),COUNTIFS(G:G,$E$4,H:H,A2),COUNTIFS(G:G,$E$5,H:H,A2),COUNTIFS(G:G,$E$6,H:H,A2),COUNTIFS(G:G,$E$7,H:H,A2),COUNTIFS(G:G,$E$8,H:H,A2),COUNTIFS(G:G,$E$9,H:H,A2))>MAX(COUNTIFS(G:G,$E$10,H:H,A2),COUNTIFS(G:G,$E$11,H:H,A2),COUNTIFS(G:G,$E$12,H:H,A2),COUNTIFS(G:G,$E$13,H:H,A2),COUNTIFS(G:G,$E$14,H:H,A2),COUNTIFS(G:G,$E$15,H:H,A2),COUNTIFS(G:G,$E$16,H:H,A2),COUNTIFS(G:G,$E$17,H:H,A2),COUNTIFS(G:G,$E$18,H:H,A2),COUNTIFS(G:G,$E$19,H:H,A2)),1,2),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$1,H:H,A2),COUNTIFS(G:G,$E$2,H:H,A2),COUNTIFS(G:G,$E$3,H:H,A2),COUNTIFS(G:G,$E$4,H:H,A2))>MAX(COUNTIFS(G:G,$E$5,H:H,A2),COUNTIFS(G:G,$E$6,H:H,A2),COUNTIFS(G:G,$E$7,H:H,A2),COUNTIFS(G:G,$E$8,H:H,A2),COUNTIFS(G:G,$E$9,H:H,A2)),1,2),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$1,H:H,A2),COUNTIFS(G:G,$E$2,H:H,A2))>MAX(COUNTIFS(G:G,$E$3,H:H,A2),COUNTIFS(G:G,$E$4,H:H,A2)),1,2),IF(COUNTIFS(G:G,$E$1,H:H,A2)>COUNTIFS(G:G,$E$2,H:H,A2),"bat","raccoon"),IF(COUNTIFS(G:G,$E$3,H:H,A2)>COUNTIFS(G:G,$E$4,H:H,A2),"bear","goat")),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$5,H:H,A2),COUNTIFS(G:G,$E$6,H:H,A2))>MAX(COUNTIFS(G:G,$E$7,H:H,A2),COUNTIFS(G:G,$E$8,H:H,A2),COUNTIFS(G:G,$E$9,H:H,A2)),1,2),IF(COUNTIFS(G:G,$E$5,H:H,A2)>COUNTIFS(G:G,$E$6,H:H,A2),"moose","turtle"),CHOOSE(IF(COUNTIFS(G:G,$E$7,H:H,A2)>MAX(COUNTIFS(G:G,$E$8,H:H,A2),COUNTIFS(G:G,$E$9,H:H,A2)),1,2),"squirrel",IF(COUNTIFS(G:G,$E$8,H:H,A2)>COUNTIFS(G:G,$E$9,H:H,A2),"snake","bird")))),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$10,H:H,A2),COUNTIFS(G:G,$E$11,H:H,A2),COUNTIFS(G:G,$E$12,H:H,A2),COUNTIFS(G:G,$E$13,H:H,A2),COUNTIFS(G:G,$E$14,H:H,A2))>MAX(COUNTIFS(G:G,$E$15,H:H,A2),COUNTIFS(G:G,$E$16,H:H,A2),COUNTIFS(G:G,$E$17,H:H,A2),COUNTIFS(G:G,$E$18,H:H,A2),COUNTIFS(G:G,$E$19,H:H,A2)),1,2),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$10,H:H,A2),COUNTIFS(G:G,$E$11,H:H,A2))>MAX(COUNTIFS(G:G,$E$12,H:H,A2),COUNTIFS(G:G,$E$13,H:H,A2),COUNTIFS(G:G,$E$14,H:H,A2)),1,2),IF(COUNTIFS(G:G,$E$10,H:H,A2)>COUNTIFS(G:G,$E$11,H:H,A2),"cat","dog"),CHOOSE(IF(COUNTIFS(G:G,$E$12,H:H,A2)>MAX(COUNTIFS(G:G,$E$13,H:H,A2),COUNTIFS(G:G,$E$14,H:H,A2)),1,2),"rabbit",IF(COUNTIFS(G:G,$E$13,H:H,A2)>COUNTIFS(G:G,$E$14,H:H,A2),"sheep","cow"))),CHOOSE(IF(MAX(COUNTIFS(G:G,$E$15,H:H,A2),COUNTIFS(G:G,$E$16,H:H,A2))>MAX(COUNTIFS(G:G,$E$17,H:H,A2),COUNTIFS(G:G,$E$18,H:H,A2),COUNTIFS(G:G,$E$19,H:H,A2)),1,2),IF(COUNTIFS(G:G,$E$15,H:H,A2)>COUNTIFS(G:G,$E$16,H:H,A2),"chicken","llama"),CHOOSE(IF(COUNTIFS(G:G,$E$17,H:H,A2)>MAX(COUNTIFS(G:G,$E$18,H:H,A2),COUNTIFS(G:G,$E$19,H:H,A2)),1,2),"pig",IF(COUNTIFS(G:G,$E$18,H:H,A2)>COUNTIFS(G:G,$E$19,H:H,A2),"horse","deer")))))
then drag until B10.
Key things that I learnt here :
Choose() is a good alternative to heavily nested if(). It had somehow helped me to 'not-getting-lost' in the formula breakdown.
Cascaded binary evaluation is a good way to break a list of repeated evaluation.
"I cannot use any additional helper cells." <-- If the OP don't mind, you may always use a helper Sheet instead. Putting this requirement really pushed the limit of excel formula. My 1st version of the solution needs > 10000 characters and it is out excel's 8192 characters limits.
Try this array formula in B2 then copy to B3:B10:
= INDEX( $G$1:$G$510,
MATCH( MAX(
IF( $H$1:$H$510 = A2,
COUNTIFS( $G$1:$G$510, $G$1:$G$510, $H$1:$H$510, $H$1:$H$510), "" ) ),
IF( $H$1:$H$510 = A2,
COUNTIFS( $G$1:$G$510, $G$1:$G$510, $H$1:$H$510, $H$1:$H$510), "" ), 0 ) )

Excel function: reference to array in cell

I have an array in cell A1 via
A1 = {=G6:J6} = {"aa"."b"."ccc".1}
Now I want to use the cell A1 for array formula in B1. Basically B1 should be
B1 = SUMPRODUKT((C6:C12)*(B6:B12=G6:J6))
But instead of the direct reference to G6:J6 I would like to use A1 instead. I just tried:
B1 = SUMPRODUKT((C6:C12)*(B6:B12=A1))
B1 = {=SUMPRODUKT((C6:C12)*(B6:B12=A1))}
But this would not work. Is there a way to make it work?
Greetings,
Peter
For questions that appeared:
Cells G6:J6 are input data for example article numbers. I want to setup the input data only once in my sheet so I have to update less data. entries in G6:J6 are strings or numbers. Let's say G6 = "aa", H6 = "b", I6 = "ccc" and J6 = 1.
Cell B1 is one point where I need to use the data. It would rather be in another sheet but for simpler examples let's assume it is cell B1. In B1 I could of course refer to G6:J6 but this makes formular less easy to read. Therefore I would like to put a reference A1 next to B1 so one can see easily what data B1 uses.
C6:C12 is some numbers and B6:B12 is some strings/numbers that maybe match G6:J6. So sumproduct should sumup the matches.
Your cell A1 contains an array formula or array range but it only contains a single value from that array or range (each Excel cell can only contain a single result value).
So you need to replace the A1 in your SUMPRODUCT with an array or range expression.
Cell A1 value shall be G6:J6
G6:J6 populated as required with {"aa","bb","ccc",1} then in B1 put following formula and check if this is what you need.
=SUMPRODUCT(C6:C12*ISNUMBER(SEARCH(B6:B12,INDIRECT(A1))))

Sumproduct with array condition

I would like to use one sumproduct formula that relies on an array of conditions of cellvalue. So basically I want to sum something when one of the entries of some cells where found before.
I can make the array of conditions work but not by cell values. In example.
Let A1 = "a", A2 = "b", B1 = 1, B2 = 2
Then
C1 = Sumproduct((A1:A100={"a"."b"})*(B1:B100)) = 3
works fine, but
C2 = Sumproduct((A1:A100=A1:A2)*(B1:B100)) = ERROR
Is there any way to put {"a"."b"} into a cell or an set of cells?
Greetings and Thanks for your help,
Peter
Disclaimer: I know I could simply write:
C2 = Sumproduct((A1:A100=A1)*(B1:B100)) + Sumproduct((A1:A100=A2)*(B1:B100))
But I would like to have a solution that is still nice to handle if 10+ conditions are on the list.
Use COUNTIF:
=SUMPRODUCT(COUNTIF(A1:A2,A1:A100)*B1:B100)
Use TRANSPOSE to make the cyclic calculation think of A1:A2 as being in a different order (... direction?) than A1:A100 and B1:B100.
=SUMPRODUCT((A1:A100=TRANSPOSE(A1:A2))*(B1:B100))
This formula is a true array formula and requires CSE.

Is it possible to display a message in an adjacent cell on Excel if there are ANY exact matches on the sheet?

I wouldn't say I was a complete beginner on Excel but I really can't work this out.
I'm putting together a database where if two cell values (alphanumeric) are the same, I need to be made aware.
So is there any formula that I can apply that will display the cell letter/number that has ANY exact match on the page. I.E:
C4 value is AEP314890 and I enter the same value in K9. Is there a formula that will display 'C4 MATCH' in cell L9?
Any help would be greatly appreciated.
Many thanks,
Matt
I would go with the countif function
=COUNTIF(B4:C7,F7) -> apply this in for example cell D4
Where B4:C7 is your range and F7 is the value that you want to compare. Now a second step would be a new IF to check if the value of D4 is higher than 0, then you can assume there exists the number already:
=IF(D4>0,"Found","not Found")
This would be the first step, now if you want to know where it is the same, you compare it with the Values simply.
Match() can help you,
http://www.techonthenet.com/excel/formulas/match_function.php
it returns the index of the matched cell in a range...
lets say
A | B
v1|v2
v3|v4
v5|v6
D1 = 'v5' E1 = Match(A1..B5, D1) = 5
you can then use then to find the Column Name and Row Name
C4 value is AEP314890 and I enter the same value in K9. Is there a
formula that will display 'C4 MATCH' in cell L9?
Just put this formula in your L9 Column .. assumed you search in C1:C100 ..
= If(Isna(Match(K9,$C$1:$C$100,0)),"","C" & TEXT(Match(K9,$C$1:$C$100,0),"###") & " Match !")

Resources