简体   繁体   English

如何在谷歌表格中使用 sumif 和 arrayformula

[英]How to use sumif with arrayformula in google sheet

From google forms, we will get inputs of vehicle nos.从google forms,我们将得到车辆编号的输入。 over a period of time, and some of these vehicle may be the same.在一段时间内,其中一些车辆可能是相同的。 Over this period, we may have noted the traffic offence made by this vehicle.在此期间,我们可能已经注意到这辆车的交通违法行为。 Is there a code/function we can write to sum of the offences the said vehicle had violated?我们是否可以编写代码/函数来汇总所述车辆违反的罪行?

Col A:Timestamp Col B:Vehicle No. (Data obtained from google form) Col C:Entry Count (obtained via VLookup/Query ~ similar to countif based on Col B) Col D:Violation Count (1 if yes, empty cell means no) Col E:Total Violation Count ~ hoping to sum the total based on Col B. Col A:Timestamp Col B:Vehicle No. (从谷歌表格获得的数据) Col C:Entry Count(通过 VLookup/Query 获得 ~ 类似于基于 Col B 的计数) Col D:Violation Count(如果是,则为 1,空单元格表示否) Col E:Total Violation Count ~ 希望根据 Col B 求和总数。

As such, with each new google form submission, the google sheet will check what is the total number of offences the said vehicle had accumulated and automate in Col E.因此,每次提交新的谷歌表单时,谷歌表格都会检查该车辆在 Col E 中累积和自动化的违规总数。

Thank you for your guidance.感谢您的指导。

If you need to have the same total amount of violations on every row for the vehicle then it would be:如果您需要在车辆的每一行有相同的违规总数,那么它将是:

=ARRAYFORMULA(
  IF(
    ROW(D:D) = 1,
      "Total Violation Count",
      IFNA(VLOOKUP(
        D:D,
        QUERY(
          D:E,
          "SELECT D, COUNT(D)
           WHERE E IS NOT NULL
           GROUP BY D"
        ),
        2,
      ))
  )
)

在此处输入图像描述

If you need a running sum for the number of violations:如果您需要违规次数的运行总和:

=ARRAYFORMULA(
  IFS(
    ROW(D:D) = 1,
      "Total Violation Count",
    A:A = "",,
    True,
      IFNA(VLOOKUP(
        MATCH(D:D, UNIQUE(FILTER(D2:D, D2:D <> "")),) * 10^INT(LOG10(ROWS(D2:D)) + 1) + ROW(D:D),
        SORT(
          {
            SEQUENCE(COUNTUNIQUE(D2:D)) * 10^INT(LOG10(ROWS(D2:D)) + 1),
            IF(SEQUENCE(COUNTUNIQUE(D2:D)), 0);
            FILTER(MATCH(D2:D, UNIQUE(FILTER(D2:D, D2:D <> "")),) * 10^INT(LOG10(ROWS(D2:D)) + 1) + ROW(D2:D), E2:E <> ""),
            MMULT(
                (FILTER(D2:D, E2:E <> "") = TRANSPOSE(FILTER(D2:D, E2:E <> "")))
              * (SEQUENCE(COUNTA(E2:E)) >= SEQUENCE(1, COUNTA(E2:E))),
              SEQUENCE(COUNTA(E2:E), 1, 1,)
            )
          }
        ),
        2
      ))
  )
)

在此处输入图像描述

Be aware that the 2nd solution has a restriction: n^2 < 10 000 000, where n is the number of records with violations.请注意,第二个解决方案有一个限制:n^2 < 10 000 000,其中 n 是违规记录的数量。 That is Google Sheets restriction on the total number of cells which is also applied to intermediary calculations.这是谷歌表格对单元格总数的限制,也适用于中间计算。

Column F:F is not used.未使用F:F列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM