如何将查询转换为arrayformula

发布于 2025-02-12 20:54:55 字数 741 浏览 2 评论 0原文

我想询问如何将此查询转换为arrayformula: = QUERY({unifer(filter($ 2:a,b $ 2:b = b2)),序列(rows(unique(unife(a $ 2:a,b $ 2:b $ 2:b = b2))))},)}, “选择col2 where col1 ='”& a2&“”)

我还将其附加在gsheet中: https://docs.google.com/spreadsheets/d/1ofbgsp42fmphedy7wtz7c3focvdjxxkvxkvxkvxkvxhdf6ac3_d4/edit#gid

= gid = 0 概念的想法是相同的如果一个月是不同的月份(但不一定是与月份进行交叉检查,因为考虑对他人进行concat,但仍将基于此处的唯一ID)

“在此处输入图像说明”

I would like to ask on how to convert this query to an 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&"'")

I also attached this in a gsheet: https://docs.google.com/spreadsheets/d/1oFbGsP42fMphedY7wtZ7C3focVDJxxkVXHdf6aC3_D4/edit#gid=0

The idea is to count sequence number that will restart to 1 for the same item if month is different month (but it wont necessarily to crosscheck with month because thinking to concat to others but is still gonna be based on the unique id here)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十雾 2025-02-19 20:54:56

尝试:

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

try:

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

enter image description here

安稳善良 2025-02-19 20:54:56

一种选择是使用应用程序脚本自定义函数。为了实现这一目标,请按照以下步骤:

  • 在您的电子表格中,选择工具>脚本编辑器打开绑定到文件的脚本。
  • 在脚本编辑器中复制此功能,然后保存项目(检查内联评论):

使用日期:

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

”输入图像描述这里“

使用ID号:

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

”在此处输入图像描述”

参考:

One option would be to use an Apps Script custom function. To achieve this, follow these steps:

  • In your spreadsheet, select Tools > Script editor to open a script bound to your file.
  • Copy this function in the script editor, and save the project (check inline comments):

Using date:

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;
  });
}
  • Now, if you go back to your spreadsheet, you can use this function like any in-built one. You just have to provide the appropriate ranges as function arguments (in this case, A2:B):

enter image description here

Using ID number:

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

enter image description here

Reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文