且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Google表格中使用CHOOSE和CONCATENATE与ARRAYFORMULA

更新时间:2022-12-06 22:46:24


但我想知道是否有一种方法可以使用CHOICE和
CONCATENATE函数与ARRAYFORUMULA。

不符合你想使用它们的方式,并且原因不同。

CONCATENATE是一个聚合函数(如SUM,AVERAGE等),它会吞噬并处理括号内的所有内容。换句话说,它不能在数组上迭代。解决方案是使用& 运算符(而不是您的最终公式)。



选择有点奇怪;无论出于何种原因,在最新版本的Google表格中,Google员工都已经移除了在第一个参数中迭代数组的能力。您列出的所有CHOOSE示例将在旧版本中用作数组公式(尽管您只需要一个ArrayFormula函数)。



对于您的具体示例,我认为您的最终的配方是***的。但是,如果您想复制以下效果:

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



您可以使用这种看起来奇怪的解决方法:

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


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?

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))