修改在 ARRAYFORMULA() 中使用 INDIRECT() 的方程式

Modifying equations that use INDIRECT() inside ARRAYFORMULA()

根据我的阅读,INDIRECT() 似乎不能与 ARRAYFORMULA() 一起使用,但是已经看到了一些针对特定情况的自定义变通解决方案。谁能帮我修改以下方程式,以便我可以对它们使用 ARRAYFORMULA()?

公式 1:

=IF($I<>"", SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$M&"6:"&$M&""),'Earnings Pivot Statement'!$A:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2,12,31)), SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$P&"6:"&$P&""),'Earnings Pivot Statement'!$A:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2,12,31)))

等式 2: =IFERROR(IFNA(SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$M&"6:"&$M&""),'Earnings Pivot Statement'!$A:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2,12,31))/O2,"-"),"-")

公式 3: =SUMIFS(INDIRECT("'Earnings Pivot Statement'!"&$P&"6:"&$P&""),'Earnings Pivot Statement'!$A:A,">="&DATE(A2,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2,12,31))

感谢我在理解如何修改这些方面能得到的任何帮助!

编辑:采纳 Erik 关于不需要 INDIRECT() 的建议,我成功地使用 OFFSET() 引用了同一组数据:

=ARRAYFORMULA(IF($I:I11<>"", SUMIFS(OFFSET('Earnings Pivot Statement'!$A, 0, $M-1, COUNTA('Earnings Pivot Statement'!$A:A)+COUNTBLANK('Earnings Pivot Statement'!$A:A),1),'Earnings Pivot Statement'!$A:A,">="&DATE(A2:A,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2:A,12,31)), SUMIFS(OFFSET('Earnings Pivot Statement'!$A, 0, $P-1, COUNTA('Earnings Pivot Statement'!$A:A)+COUNTBLANK('Earnings Pivot Statement'!$A:A),1),'Earnings Pivot Statement'!$A:A,">="&DATE(A2:A,1,1),'Earnings Pivot Statement'!$A:A,"<="&DATE(A2:A,12,31))))

但是,ARRAYFORMULA() 目前仅填充 1 个单元格,不确定原因

您正在从数据透视表 table 中查找数据,这似乎是一个不必要的步骤。尝试这样的事情直接从 'Earnings Input':

中获取总数
=query( 
  'Earnings Input'!A1:G, 
  "select year(A), sum(G) 
   where B is not null 
   group by year(A) 
   label year(A) 'Year', sum(G) 'Total' ", 
  1 
)

=arrayformula( 
  iferror( 
    vlookup( 
      G18:G, 
      query( 
        'Earnings Input'!A1:G, 
        "select year(A), sum(G) 
         where B " & if(len(I11), "= '" & I11 & "' ", "is not null") & "
         group by year(A)", 
        1 
      ), 
      2, false 
    ) 
  ) 
)

这些公式不需要任何辅助列。单元格 I11 是一个 drop-down 列表,可让您 select 过滤依据的名称,或留空以显示全部。

额外的数据点可以这样获得:

=arrayformula( if( not(len(G5)) * len(F9:F), "-", iferror( F9:F / E9:E ) ) )

=arrayformula( 
  if( 
    not(len(G5)) * len(F9:F), 
    "-", 
    iferror( 100% - G9:G / isnumber(G9:G) ) 
  ) 
)

=if( 
  len(G5), 
  G5 & " % (" & to_text(round(average(G9:G), 2)) & ")", 
  "No filter" 
)

看到新的 Solution3 sheet.

上面的解决方案仍然有点冗长,主要是因为您选择的报告格式。一次显示所有类别的数据通常更容易。要了解那会是什么样子,试试这个:

=query( 
  'Earnings Input'!A1:G, 
  "select year(A), sum(G) 
   where B is not null 
   group by year(A) 
   pivot B 
   label year(A) 'Year', sum(G) 'Total' ", 
  1 
)

=arrayformula( 
  if( 
    isnumber(B3:J15) * isnumber(B3:B15) * isnumber(B3:J3), 
    B3:J15 / B3:B15, 
    B3:J15 
  ) 
)

看到新的 Solution2 sheet.