简体   繁体   English

使用 Google 表格 ARRAYFORMULA 连接基于每行从最低值到最高值的项目系列

[英]Using Google Sheets ARRAYFORMULA to Concatenate Series of Item Based from Lowest to Highest Values per Row

I have a table with three Columns: Column A: name of Item, Column B: Lowest value of series, Column C: the Highest value of series.我有一个包含三列的表格:A 列:项目名称,B 列:系列的最低值,C 列:系列的最高值。 enter image description here在此处输入图像描述

What I want to achieve is:我想要实现的是:

  1. Generate series of item sequence from lowest number to highest number per row生成每行从最低编号到最高编号的一系列项目序列

So Apple 7 9 will yield: "Apple_7", "Apple_8", "Apple_9"所以 Apple 7 9 将产生:“Apple_7”、“Apple_8”、“Apple_9”

  1. Concatenate/Join such sequence per row into Column D So将每行的此类序列连接/加入 D 列 So

    Item物品 From Until直到 Result结果
    Apple苹果 7 7 9 9 "Apple_7, Apple_8, Apple_9" “Apple_7、Apple_8、Apple_9”
    Berry浆果 3 3个 8 8个 "Berry_3, Berry_4, Berry_5, Berry_6, Berry_7, Berry_8" “Berry_3、Berry_4、Berry_5、Berry_6、Berry_7、Berry_8”
  2. Doing it all using one Arrayformula, so that new row added can be automatically calculated.使用一个 Arrayformula 完成所有操作,以便可以自动计算添加的新行。

Here is example sheet: https://docs.google.com/spreadsheets/d/1R5raKmmt5-aOIorAZGHjv_-fdySKWjCMB_FRQwm1vag/edit#gid=0这是示例表: https://docs.google.com/spreadsheets/d/1R5raKmmt5-aOIorAZGHjv_-fdySKWjCMB_FRQwm1vag/edit#gid=0

I tried in Column D:我在 D 列中尝试过:

arrayformula(textjoin(", ",true,arrayformula(A3:A&"_"&sequence(1,C3:C-B3:B+1,B3:B,1))))

Apparently, the sequence function only take value from Column B and join it in first row.显然,序列 function 仅从 B 列获取值并将其加入第一行。

Any help will be appreciated.任何帮助将不胜感激。

Try below BYROW() formula (see your file, harun24hr sheet).试试下面BYROW()公式(见你的文件,harun24hr 表)。

=BYROW(A3:INDEX(A3:A,COUNTA(A3:A)),LAMBDA(x,TEXTJOIN(";",1,INDEX(x&"_"& SEQUENCE(INDEX(C:C,ROW(x))-INDEX(B:B,ROW(x))+1,1,INDEX(B:B,ROW(x)))))))
  • Here A3:INDEX(A3:A,COUNTA(A3:A)) will return a array of values as well cell reference from A3 to last non empty cell in column A (Assume you do not have any blank rows inside data).这里A3:INDEX(A3:A,COUNTA(A3:A))将返回一个值数组以及从A3到 A 列中最后一个非空单元格的单元格引用(假设数据中没有任何空白行)。 If you have blank row, then you have to use different approach.如果你有空行,那么你必须使用不同的方法。 See this post by @TheMaster请参阅@TheMaster 的这篇文章

  • Then LAMBDA() will apply TEXTJOIN() and SEQUENCE() function for each cell of B as well as C column .然后LAMBDA()将对B 的每个单元格以及 C 列应用TEXTJOIN()SEQUENCE() function。

  • SEQUENCE() will make series from start to end number and by concatenating A column and will generate your desired strings. SEQUENCE()将从开始到结束编号并通过连接 A 列来制作系列,并将生成您想要的字符串。

  • Finally TEXTJOIN() will join all those strings with delimiter to a single cell.最后TEXTJOIN()会将所有带有分隔符的字符串连接到一个单元格中。

在此处输入图像描述

try REDUCE:尝试减少:

=INDEX(QUERY(REDUCE(, A3:INDEX(A:A, MAX(ROW(A:A)*(A:A<>""))), 
 LAMBDA(x, a, {x; JOIN(, LAMBDA(i, f, u, i&"_"&SEQUENCE(1, u-f+1, f)&";")
 (a, OFFSET(a,,1), OFFSET(a,,2)))})), "offset 1", ))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM