问题
Im working on what I thought would be a fairly straight forward arrayformula where I only needed a single cell entry instead of having to copy it down to 100+ rows.
I am working on a spreadsheet for use with the beast shape, elemental body, and plant shape spells in Pathfinder.
My table looks like
_________A___________B________C
1___Spell name_____Type_____Size
Where A2 will contain the arrayformula. B2:B will contain Animal, Plant, Elemental, Magical Beast. C2:C will contain the range of sizes.
I have tried
ARRAYFORMULA(if(B2:B<>"",CONCATENATE(if(AND(B2:B="Animal", OR(C2:C="Small", C2:C="Medium")),"Beast Shape 1","Fail BS1"),if(AND(B2:B="Animal", OR(C2:C="Tiny", C2:C="Large")),"Beast Shape 2","Fail BS2")),"Fail Other"))
and
=ARRAYFORMULA(if(B2:B<>"",if(and(B2:B="Animal",C2:C="Small"),"Beast Shape 1", "not"), "if fail"))
But they produce incorrect output. I have tried several others as well but with various issues, usually not being propagated down all the cells, or just having the wrong information. Even when I try using only a single statement.
Originally my plan was to have a concat statement which contained multiple if statements which would produce the spell name or nothing. It looked something like
arrayformula(if(b2:b<>"",concatenate(if(and(b2:b="Animal",OR(c2="small",c2="medium")), "Beast shape 1", ""), if(and(b2:b="Animal",OR(c2="tiny",c2="large")), "Beast shape 2", ""))
However the output is wrong, and I havent been able to figure out why. Ive seen comments in places which suggests AND and OR are not valid as they have single output statements, and that concatenate must be replaced with &, but even when those are removed it does not work.
回答1:
Replace AND with *
and OR with +
:
if(and(b2:b="Animal",OR(c2="small",c2="medium"))
becomes:
if( (b2:b="Animal") * ((c2:c="small") + (c2:c="medium")) )
array-formula must work with that.
来源:https://stackoverflow.com/questions/44402496/google-sheets-arrayformula-with-nested-if-statements