如何将这个Google表格公式转换成数组公式。

huangapple go评论53阅读模式
英文:

How to make this Google Sheet formula, into an array formula

问题

We have a Google Sheet table that's the target for a Google Form. It has multiple choice responses in column M that are strings containing numbers.

Example: 3. The mentor team clearly assigned..., 4. The mentor team knew the..., 5. The mentor team knew the choice..., 7. The mentor team came early on..., 8. The children were...

We need an array formula to:

  • extract the numbers
  • sum them
  • for each non-empty row in column M

We have the below working formula, but we need it to be an array formula because the spreadsheet is ever growing with new entries from the form.

=SUM(IFERROR(SPLIT(REGEXREPLACE(M2,"[^\d\.]+"," "), " ")))

英文:

We have a Google Sheet table that's the target for a Google Form. It has multiple choice responses in column M that are strings containing numbers.

Example: 3. The mentor team clearly assigned..., 4. The mentor team knew the..., 5. The mentor team knew the choice..., 7. The mentor team came early on..., 8. The children were...

We need an array formula to:

  • extract the numbers
  • sum them
  • for each non-empty row in column M

We have the below working formula, but we need it to be an array formula because the spreadsheet is ever growing with new entries from the form.

=SUM(IFERROR(SPLIT(REGEXREPLACE(M2,"[^\d\.]+"," ")," ")))

答案1

得分: 2

以下是翻译好的部分:

尝试以下内容

=BYROW(FILTER(M2:M,M2:M<>""),LAMBDA(sx, SUM(IFERROR(SPLIT(REGEXREPLACE(sx,"[^\d.]+"," "), " ")))))
这将跳过任何空行,但会“扰乱”答案的顺序。

要在空行保留0,请使用此公式

=BYROW(M2:M,LAMBDA(sx, SUM(IFERROR(SPLIT(REGEXREPLACE(sx,"[^\d.]+"," "), " ")))))

英文:

Try the following

=BYROW(FILTER(M2:M,M2:M&lt;&gt;&quot;&quot;),LAMBDA(sx, 
         SUM(IFERROR(SPLIT(REGEXREPLACE(sx,&quot;[^\d\.]+&quot;,&quot; &quot;),&quot; &quot;)))))

This will skip any empty rows but will "mess" with the order of the answers.

To keep 0s for empty rows use this formula

=BYROW(M2:M,LAMBDA(sx, 
   SUM(IFERROR(SPLIT(REGEXREPLACE(sx,&quot;[^\d\.]+&quot;,&quot; &quot;),&quot; &quot;)))))

答案2

得分: 1

以下是要翻译的内容:

备选方案

您还可以利用Google表格中提供的MAPREDUCE函数来实现此目标,如以下示例所示:

=MAP(ARRAYFORMULA(REGEXREPLACE(FILTER(M2:M, NOT(ISBLANK(M2:M))), &quot;[^\d\.]+&quot;, &quot;.&quot;)), LAMBDA(cell, REDUCE(0,SPLIT(cell,&quot;.&quot;),LAMBDA(accumulator, current_value, accumulator+current_value))))

此示例公式遵循以下流程:

  1. 获取列M中每个单元格中的所有数字。
  2. 使用MAP函数逐个单元格处理每个收集到的数字。
  3. 每个单元格将被传递到SPLIT函数,以分隔数字。
  4. 一旦所有数字都被分隔开,它们将被传递到REDUCE函数以计算它们的总和。
  5. 返回每个值的单元格总和。

演示

如何将这个Google表格公式转换成数组公式。

参考:

英文:

Alternate Solution

You can also achieve this by utilizing the MAP and REDUCE functions available in Google Sheets, as demonstrated in the following example:

=MAP(ARRAYFORMULA(REGEXREPLACE(FILTER(M2:M, NOT(ISBLANK(M2:M))), &quot;[^\d\.]+&quot;, &quot;.&quot;)), LAMBDA(cell, REDUCE(0,SPLIT(cell,&quot;.&quot;),LAMBDA(accumulator, current_value, accumulator+current_value))))

This sample formula follows the following flow:

  1. Get all of the numbers in each of the cells in Column M.
  2. Process each gathered number using the MAP function, cell by cell.
  3. Each cell will be passed into the SPLIT function, to separate the numbers.
  4. Once all the numbers have been separated, they will be passed into the REDUCE function to calculate their sum.
  5. Return the total per cell of each value.

Demo

如何将这个Google表格公式转换成数组公式。

References:

答案3

得分: 1

=ARRAYFORMULA(BYROW(IFERROR(SPLIT(REGEXREPLACE(M2:M,"[^\d.]+"," "), " ")), LAMBDA(row, SUM(row))))

或者:

=MAP(M2:M, LAMBDA(z, SUM(IFERROR(SPLIT(REGEXREPLACE(z, "[^\d.]+", " "), " ")))))

英文:

You could also try:

=ARRAYFORMULA(BYROW(IFERROR(SPLIT(REGEXREPLACE(M2:M,&quot;[^\d\.]+&quot;,&quot; &quot;),&quot; &quot;)),LAMBDA(row,SUM(row))))

Or:

=MAP(M2:M,LAMBDA(z,SUM(IFERROR(SPLIT(REGEXREPLACE(z,&quot;[^\d\.]+&quot;,&quot; &quot;),&quot; &quot;)))))

huangapple
  • 本文由 发表于 2023年5月13日 08:11:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76240550.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定