Using CHOOSE and CONCATENATE with ARRAYFORMULA in

2019-08-15 14:21发布

问题:

I was trying to create an array of dates in a column, and I ran into trouble using the CHOOSE and CONCATENATE formulas with ARRAYFORUMULA. Is there a way to solve the following problems:

Column I contains dates; the first date falls on a Weds; all of the other dates fall on a Monday

When I use
=CONCATENATE(ARRAYFORMULA(Text($I9:$I12,"ddd")),"111") =ARRAYFORMULA(CONCATENATE((Text($I9:$I14,"ddd")),"111")) =ARRAYFORMULA(CONCATENATE((ARRAYFORMULA(Text($I9:$I14,"ddd"))),"111"))

I get the following single-cell response:
WedMonMonMon111

What I am trying to get is:
Wed 111
Mon 111
Mon 111
Mon 111

When I use the following equations:

=ARRAYFORMULA(CHOOSE( weekday(I10:I14), "1 Sun", "2 Mon", "3 Tue", "4 Wed", "5 Thurs", "6 Fri", "7 Sat"))

=ARRAYFORMULA(CHOOSE(ARRAYFORMULA(weekday(ARRAYFORMULA(I10:I14))), "1 Sun", "2 Mon", "3 Tue", "4 Wed", "5 Thurs", "6 Fri", "7 Sat"))

=ARRAYFORMULA(CHOOSE( ARRAYFORMULA(weekday(I10:I14)), "1 Sun", "2 Mon", "3 Tue", "4 Wed", "5 Thurs", "6 Fri", "7 Sat"))

=ARRAYFORMULA(CHOOSE(weekday(ARRAYFORMULA(I10:I14)), "1 Sun", "2 Mon", "3 Tue", "4 Wed", "5 Thurs", "6 Fri", "7 Sat"))

I get the following single-cell response:
2 Mon

What I am trying to get is 1 Wed
2 Mon
2 Mon
2 Mon
2 Mon

I can get the date format listed above using the following equation:
=ARRAYFORMULA(weekday(I9:I14)& " "&Text(I9:I14, "ddd"))

But I was wondering if there was a way to use the CHOOSE and CONCATENATE functions with ARRAYFORUMULA. Does anyone know anything about this?

回答1:

But I was wondering if there was a way to use the CHOOSE and CONCATENATE functions with ARRAYFORUMULA.

Not in the way you want to use them, and for different reasons.

CONCATENATE is an "aggregating" function (like SUM, AVERAGE etc) that will "gobble up" and process everything within the parentheses. In other words, it can't be iterated over an array. The solution is to use the & operator instead (as you have done in your final formula).

CHOOSE is a bit strange; for whatever reason, in the newest version of Sheets, the Googlers have removed the ability for it to be iterated over an array in the first argument. All of those CHOOSE examples you listed will work as an array formula in the old version (although you only need one ArrayFormula function).

For your specific example, I think your final formula is best. But if you wanted to replicate the expected effect of:

=ArrayFormula(CHOOSE(range,"element 1","element 2",...))

you could use this odd-looking workaround:

=ArrayFormula(HLOOKUP("element 1",{"element 1";"element 2";...},range,0))