繁体   English   中英

如何将查询转换为数组公式

[英]How to convert query to arrayformula

我想问一下如何将此查询转换为数组公式: =query({unique(filter(A$2:A,B$2:B=B2)),sequence(rows(unique(filter(A$2:A,B$2:B=B2))))},"select Col2 where Col1 = '"&A2&"'")

我还在 gsheet 中附加了这个: https ://docs.google.com/spreadsheets/d/1oFbGsP42fMphedY7wtZ7C3focVDJxxkVXHdf6aC3_D4/edit#gid=0

这个想法是计算如果月份是不同的月份,同一项目将重新开始为 1 的序列号(但不一定要与月份交叉检查,因为考虑与其他人连接,但仍将基于此处的唯一 ID)

在此处输入图像描述

一种选择是使用 Apps Script 自定义函数 为此,请按照下列步骤操作:

  • 在您的电子表格中,选择工具 > 脚本编辑器以打开绑定到您的文件的脚本。
  • 在脚本编辑器中复制此函数,并保存项目(检查内联注释):

使用日期:

function myFunction(values) {
  values = values.filter(r => r[0].length); // Remove empty rows
  return values.map((row,i) => { // Loop through rows
    const [item, date] = row;
    const month = date.getMonth();
    const year = date.getFullYear();
    const monthRows = values.filter(r => r[1].getMonth() === month && r[1].getFullYear() === year); // Filter month rows
    const itemIndex = [...new Set(monthRows.map(r => r[0]))].indexOf(item); // Check index of this item in current month
    return itemIndex + 1;
  });
}
  • 现在,如果您返回电子表格,您可以像使用任何内置功能一样使用此功能。 您只需提供适当的范围作为函数参数(在本例中为A2:B ):

在此处输入图像描述

使用身份证号码:

function myFunction(values) {
  return values.map((row,i) => { // Loop through rows
    const [item, id] = row;
    if (item.length) {
      const idRows = values.filter(r => id === r[1]); // Filter id
      const itemIndex = [...new Set(idRows.map(r => r[0]))].filter(String).indexOf(item); // Check index of this item in current id
      return itemIndex + 1;
    }
  });
}

在此处输入图像描述

参考:

尝试:

=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B, SORT(SPLIT(FLATTEN(TRANSPOSE(
 SPLIT(FLATTEN(QUERY(QUERY(QUERY({A2:A&B2:B&"×"&
 VLOOKUP(A2:A, {A2:A, TEXT(ROW(A2:A), "00000")}, 2, ), B2:B}, 
 "select max(Col1) group by Col1 pivot Col2"), 
 "offset 1", 0),,9^9)), " "))&"×"&SEQUENCE(COUNTUNIQUE(A2:A))), "×")), 3, )))

在此处输入图像描述

暂无
暂无

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

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