如何根据特定条件选择前10个值?

时间:2019-05-31 08:48:51

标签: google-sheets google-sheets-formula array-formulas

我想根据收入在三个不同的星期中选择排名前十的产品:

enter image description here

星期自动更改(例如,本周我是5/27,但是下周它将自动更新为6/3)。

我的数据集每周自动更新,外观如下:

enter image description here

我尝试过使用INDEX MATCH和LARGE,但是我不知道如何自动执行。

我希望输出结果是一个公式,该公式将在每次数据集更新时自动增加其他几周的收入。

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

好吧,好吧,我在共享工作表之前生成了一些随机数据,结果发现最好的一周是上周:

enter image description here

工作表数据中的原始数据:

enter image description here

公式:

B1

=index(Data!B1:1,COUNTA(Data!1:1)-1)

D1

=index(Data!B1:1,COUNTA(Data!1:1)-2)

F1

=ArrayFormula(index(Data!B1:1,match(max(mmult(transpose(row(Data!B2:index(Data!B2:B,counta(A:A)-1)))^0,Data!B2:index(Data!B2:Z,counta(A:A)-1,counta(Data!1:1)-1))),
mmult(transpose(row(Data!B2:index(Data!A2:B,counta(A:A)-1)))^0,Data!B2:index(Data!B2:Z,counta(A:A)-1,counta(Data!1:1)-1)),0)))

A3

=sortn({Data!A2:A,index(Data!B2:Z,0,counta(Data!1:1)-1)},10,0,2,false)

C3

=sortn({Data!A2:A,index(Data!B2:Z,0,counta(Data!1:1)-2)},10,0,2,false)

E3

=sortn({Data!A2:A,index(Data!B2:Z,0,match(F1,Data!B1:1,0))},10,0,2,false)

答案 1 :(得分:1)

B4:

={ARRAYFORMULA(INDIRECT("Dataset!"&ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21),
 WEEKNUM(INDIRECT("Dataset!A1:"&ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4))),
 ARRAYFORMULA(SUM(INDIRECT("Dataset!"&ADDRESS(2, MATCH(INDIRECT("Dataset!"&
 ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21), WEEKNUM(INDIRECT("Dataset!A1:"&
 ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4)),
 Dataset!1:1, 0),4)&":"&ADDRESS(ROWS(Dataset!A:A), MATCH(INDIRECT("Dataset!"&
 ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21), WEEKNUM(INDIRECT("Dataset!A1:"&
 ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4)), Dataset!1:1, 0),4))))}

B5:

={ARRAYFORMULA(INDEX(Dataset!B1:1, MATCH(MAX(MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!B2:B, COUNTA(Dataset!A:A)-1)))^0, 
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, 
 COUNTA(Dataset!1:1)-1))), MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!A2:B, COUNTA(Dataset!A:A)-1)))^0,
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, COUNTA(Dataset!1:1)-1)), 0))),
 ARRAYFORMULA(SUM(INDIRECT("Dataset!"&ADDRESS(2, MATCH(INDEX(Dataset!B1:1, 
 MATCH(MAX(MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!B2:B, COUNTA(Dataset!A:A)-1)))^0, 
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, 
 COUNTA(Dataset!1:1)-1))), MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!A2:B, COUNTA(Dataset!A:A)-1)))^0,
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, COUNTA(Dataset!1:1)-1)), 0)), 
 Dataset!1:1, 0), 4)&":"&ADDRESS(ROWS(Dataset!A:A), MATCH(INDEX(Dataset!B1:1, 
 MATCH(MAX(MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!B2:B, COUNTA(Dataset!A:A)-1)))^0, 
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, 
 COUNTA(Dataset!1:1)-1))), MMULT(TRANSPOSE(ROW(
 Dataset!B2:INDEX(Dataset!A2:B, COUNTA(Dataset!A:A)-1)))^0,
 Dataset!B2:INDEX(Dataset!B2:Z, COUNTA(Dataset!A:A)-1, 
 COUNTA(Dataset!1:1)-1)), 0)), Dataset!1:1, 0), 4))))}

B6:

={ARRAYFORMULA(INDIRECT("Dataset!"&ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21),
 WEEKNUM(INDIRECT("Dataset!A1:"&ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4)))-7,
 ARRAYFORMULA(SUM(INDIRECT("Dataset!"&ADDRESS(2, MATCH(INDIRECT("Dataset!"&
 ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21), WEEKNUM(INDIRECT("Dataset!A1:"&
 ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4))-7,
 Dataset!1:1, 0),4)&":"&ADDRESS(ROWS(Dataset!A:A), MATCH(INDIRECT("Dataset!"&
 ADDRESS(1, MATCH(WEEKNUM(TODAY(), 21), WEEKNUM(INDIRECT("Dataset!A1:"&
 ADDRESS(1, COUNTA(Dataset!A1:1), 4)), 21), 0), 4))-7, Dataset!1:1, 0), 4))))}

E5:

=ARRAYFORMULA({
 QUERY({Dataset!$A$2:$A, INDIRECT("Dataset!"&
 ADDRESS(2,                      MATCH(F$3, Dataset!$A$1:$1, 0), 4)&":"&
 ADDRESS(ROWS(Dataset!$A2:$A)+1, MATCH(F$3, Dataset!$A$1:$1, 0), 4))}, 
 "order by Col2 desc limit 10", 0),
 QUERY({Dataset!$A$2:$A, INDIRECT("Dataset!"&
 ADDRESS(2,                      MATCH(H$3, Dataset!$A$1:$1, 0), 4)&":"&
 ADDRESS(ROWS(Dataset!$A2:$A)+1, MATCH(H$3, Dataset!$A$1:$1, 0), 4))}, 
 "order by Col2 desc limit 10", 0),
 QUERY({Dataset!$A$2:$A, INDIRECT("Dataset!"&
 ADDRESS(2,                      MATCH(J$3, Dataset!$A$1:$1, 0), 4)&":"&
 ADDRESS(ROWS(Dataset!$A2:$A)+1, MATCH(J$3, Dataset!$A$1:$1, 0), 4))},
 "order by Col2 desc limit 10", 0)})

0