![](/img/trans.png)
[英]How to convert this FILTER + COUNTA() into an Arrayformula on Google Sheets?
[英]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.