Google表格中的查询异常

时间:2019-06-05 20:37:00

标签: google-sheets google-sheets-formula array-formulas google-sheets-query gs-vlookup

我有这张桌子:

      A                     B
1     Company Code          Year
2     61.490.561/0001-00    2018
3     61.490.561/0001-00    2017
4     61.490.561/0001-00    2016
5     84.586.205/0001-90    2018
6     84.586.205/0001-90    2017
7     84.586.205/0001-90    2016
8     01.009.357/0001-01    2017
9     01.009.357/0001-01    2015
10    01.009.354/0001-60    2017
11    01.009.354/0001-60    2016
12    01.009.355/0001-04    2016
13    01.009.355/0001-04    2015
14    04.185.877/0001-55    2018
15    04.185.877/0001-55    2017
16    04.185.877/0001-55    2016
    ...

我需要:

  1. 检查去年的每个公司代码
  2. 创建一个新表,其中每个公司代码都有五行,Year值将遵循以下原理:去年+1,去年+2,去年+3,去年+4,去年+5

在上面的示例中,它看起来像这样:

      A                     B
1     Company Code          Year
2     61.490.561/0001-00    2023
3     61.490.561/0001-00    2022
4     61.490.561/0001-00    2021
5     61.490.561/0001-00    2020
6     61.490.561/0001-00    2019
7     84.586.205/0001-90    2023
8     84.586.205/0001-90    2022
9     84.586.205/0001-90    2021
10    84.586.205/0001-90    2020
11    84.586.205/0001-90    2019
12    01.009.357/0001-01    2022
13    01.009.357/0001-01    2021
14    01.009.357/0001-01    2020
15    01.009.357/0001-01    2019
16    01.009.357/0001-01    2018
17    01.009.354/0001-60    2022
18    01.009.354/0001-60    2021
19    01.009.354/0001-60    2020
20    01.009.354/0001-60    2019
21    01.009.354/0001-60    2018
22    01.009.355/0001-04    2021
23    01.009.355/0001-04    2020
24    01.009.355/0001-04    2019
25    01.009.355/0001-04    2018
26    01.009.355/0001-04    2017
27    04.185.877/0001-55    2023
28    04.185.877/0001-55    2022
29    04.185.877/0001-55    2021
30    04.185.877/0001-55    2020
31    04.185.877/0001-55    2019

我尝试使用查询,但是这对于我的技能而言似乎相当高级。我该如何开始呢?

2 个答案:

答案 0 :(得分:1)

=ARRAYFORMULA({A1:B1; SORT({
 QUERY(UNIQUE(IFERROR(VLOOKUP(INDEX(SORT(A2:B, 1, 1, 2, 0), , 1), 
 SORT(A2:B, 1, 1, 2, 0), {1, 2}, 0))), "select Col1,Col2+1 label Col2+1''", 0);
 QUERY(UNIQUE(IFERROR(VLOOKUP(INDEX(SORT(A2:B, 1, 1, 2, 0), , 1), 
 SORT(A2:B, 1, 1, 2, 0), {1, 2}, 0))), "select Col1,Col2+2 label Col2+2''", 0);
 QUERY(UNIQUE(IFERROR(VLOOKUP(INDEX(SORT(A2:B, 1, 1, 2, 0), , 1), 
 SORT(A2:B, 1, 1, 2, 0), {1, 2}, 0))), "select Col1,Col2+3 label Col2+3''", 0);
 QUERY(UNIQUE(IFERROR(VLOOKUP(INDEX(SORT(A2:B, 1, 1, 2, 0), , 1), 
 SORT(A2:B, 1, 1, 2, 0), {1, 2} ,0))) ,"select Col1,Col2+4 label Col2+4''", 0);
 QUERY(UNIQUE(IFERROR(VLOOKUP(INDEX(SORT(A2:B, 1, 1, 2, 0), , 1), 
 SORT(A2:B, 1, 1, 2, 0), {1, 2}, 0))), "select Col1,Col2+5 label Col2+5''", 0)}, 
 1, 1, 2, 0)})

0

答案 1 :(得分:1)

基本上,这是我第一次尝试使用Google Spreadsheets。

如果您在A2的第二个标签(Sheet2)中有什么?

=INDEX(UNIQUE(Sheet1!$A$2:$A$16),ROUNDUP((ROW()-1)/5))

B2中,

=MAXIFS(Sheet1!$B$2:$B$16,Sheet1!$A$2:$A$16,A2)+COUNTIF(A2:INDEX($A:$A,COUNTA(A:A)-1),A2)

并向下拖动两个...

enter image description here