这是一个类似的问题,与使用sumif的arrayformula在多种条件下与通配符结合使用通配符,以选择给定条件的所有值,但要在给定的一年的所有月份中获得第一列的总和。我试图推断 @player0提供的相同解决方案,但是 by 不起作用,因为我想获得一年中的每个月的结果,无论源。这是示例:
在列中 g
中我们有不同的过滤条件,它可以包括一个特殊令牌: all
包括每个值的所有值标准。在这一年中,我们可以选择要将结果总结为一年中的每个月的给定年份。
i
使用引用问题的类似想法具有预期的结果,但是它不能在 arrayformula
(查询结果不展开)中表达。
=IFNA(QUERY(QUERY(FILTER($A$2:$E,
IF($G$2="All", $B$2:$B<>"×", $B$2:$B=$G$2),
IF($G$4="All", $C$2:$C<>"×", $C$2:$C=$G$4),
IF($G$6="All", $D$2:$D<>"×", $D$2:$D=$G$6),
YEAR($E$2:$E) = $G$8
),
"select sum(Col1) where month(Col5) =" & MONTH($H2) - 1),
"offset 1", 0),"")
列 > j 数组尝试不起作用,因为我们不能使用 sumif
使用虚拟范围,可以通过使用 filter
创建辅助列来解决它,但是我我正在寻找不需要的解决方案。
=Arrayformula(if(not(ISBLANK(H2:H)), sumif(
Filter(FILTER($A$2:$E, IF($G$3="All", $B$2:$B<>"×",
$B$2:$B=$G$3), IF($G$5="All", $C$2:$C<>"×", $C$2:$C=$G$5),
IF($G$7="All", $D$2:$D<>"×", $D$2:$D=$G$7),
YEAR($E$2:$E) = $G$9),{1,0,0,0,0}), H2:H,
Filter(FILTER($A$2:$E, IF($G$3="All", $B$2:$B<>"×",
$B$2:$B=$G$3), IF($G$5="All", $C$2:$C<>"×", $C$2:$C=$G$5),
IF($G$7="All", $D$2:$D<>"×", $D$2:$D=$G$7),
YEAR($E$2:$E) = $G$9), {0,0,0,0,1})
),))
这是样本电子表格:
This is a similar problem to Using ARRAYFORMULA with SUMIF for multiple conditions combined with a wildcard to select all values for a given condition, but trying to get the sum of the first column by all months of a given year. I was trying to extrapolate the same solution provided by @player0, but group by
doesn't work because I would like to get a result for each month of the year, regardless of the month's data on the source. Here is the sample:

In column G
we have different filter conditions and it can include a special token: ALL
to include all values for each criterion. For the year we can select the given year for which we want to sum the result by each month of the year.
Column I
has the expected result using the similar idea of the referred question, but it cannot be expressed in an ArrayFormula
(query result doesn't expand):
=IFNA(QUERY(QUERY(FILTER($A$2:$E,
IF($G$2="All", $B$2:$B<>"×", $B$2:$B=$G$2),
IF($G$4="All", $C$2:$C<>"×", $C$2:$C=$G$4),
IF($G$6="All", $D$2:$D<>"×", $D$2:$D=$G$6),
YEAR($E$2:$E) = $G$8
),
"select sum(Col1) where month(Col5) =" & MONTH($H2) - 1),
"offset 1", 0),"")
On column J
the array try doesn't work because we cannot use the virtual range with SUMIF
it can be resolved by creating auxiliary columns with the FILTER
, but I am looking for a solution that doesn't require that.
=Arrayformula(if(not(ISBLANK(H2:H)), sumif(
Filter(FILTER($A$2:$E, IF($G$3="All", $B$2:$B<>"×",
$B$2:$B=$G$3), IF($G$5="All", $C$2:$C<>"×", $C$2:$C=$G$5),
IF($G$7="All", $D$2:$D<>"×", $D$2:$D=$G$7),
YEAR($E$2:$E) = $G$9),{1,0,0,0,0}), H2:H,
Filter(FILTER($A$2:$E, IF($G$3="All", $B$2:$B<>"×",
$B$2:$B=$G$3), IF($G$5="All", $C$2:$C<>"×", $C$2:$C=$G$5),
IF($G$7="All", $D$2:$D<>"×", $D$2:$D=$G$7),
YEAR($E$2:$E) = $G$9), {0,0,0,0,1})
),))
Here is the sample spreadsheet:
https://docs.google.com/spreadsheets/d/1Lqjim3c_j8KNr_7LVlKjlR4BXi9_1HFoGDuwsuX1XS0/edit?usp=sharing
发布评论
评论(2)
尝试:
try:
此公式在样本
Sheet1
的单元L2
中。这是一个sumif()
,它使用正则和mmult
来创建3'
s的数组,其中满足条件和&amp;'符合“ SUMIF”标准的月份。详细说明
(公式,然后在以下几行中)
生成
1x3
带有g3,g5,g7,g7
值的数组,如果“ all”将被空字符串替换。如果是(“ all”,all”,“ all”)返回:
在(“全部”,“ ALL”)的情况下。(,,,)
。替代
的结果将是在<代码> REGEXMATCH返回与
b2相同大小的数组
)值和函数n()
将其转换为(0
|1
)值。乘以两个矩阵:
mx3
x3x1
并返回数组mx1
。如果满足所有过滤器条件,将在给定单元格上返回数字3
(我们有三个条件),否则比3
低的数字。计算细胞
e2的上个月的最后一天:我们需要将这些日期与代表本月第一天的
H2:H
中的日期进行比较。range
:将包含一个mx1
的数组,其中一个值:{0,1,1,2,3}
,取决于如何满足许多条件。它附加了&amp; eomonth(e2:e,-1)+1
。请记住,日期存储为整数编号。标准
:3&amp; h2:h13
参考日期由数字前缀3
。。
sum_range
:范围a2:a
我们要基于范围和标准匹配的总和,因此只有3
值的行mmult
将被考虑。在这里,在过滤器的情况下,结果具有值:
此解决方案当
所有
doken不使用:note :与预期结果和 @player0解决方案的唯一区别是,当没有匹配时,它返回
0
。This formula is in cell
L2
of your sampleSheet1
. It is asumif()
that uses a regex andMMULT
to create an array of3'
s where the conditions are met and &'s it with the month for the 'sumif' criterium.Detail Explanation
(The formula, then in the following lines the explanation)
Generate a
1x3
array withG3,G5,G7
values, if"ALL"
then will be replaced by empty string. In case of ("ALL", ALL", "ALL") returns:(,,)
. The result ofSUBSTITUTE
will be the regular expression to be used inREGEXMATCH
. In case of ("ALL", ALL", "ALL")REGEXMATCH
will return(TRUE, TRUE, TRUE)
on each row.Return an array of the same size as
B2:D
(let's sayMx3
array) where the condition are met (TRUE
|FALSE
) values and the functionN()
converts it into (0
|1
) values.Multiplies two matrixes:
Mx3
x3x1
and returns an arrayMx1
. If all filters conditions are satisfied will return on a given cell the number3
(we have three conditions), otherwise a number lower than3
.Calculate the last day of the previous month of the cells
E2:E
and add one day resulting the first day of the month ofE2:E
. We need to compare such dates with the dates inH2:H
that represent the first day of the month.range
: will contain an array ofMx1
with one of the values:{0,1,2,3}
depending on how many conditions are met. It appends&EOMONTH(E2:E,-1)+1
. Remember dates are stored as an integer number.criterium
:3&H2:H13
the reference dates prefixed by number3
.sum_range
: The rangeA2:A
we want to sum based on the range and criterium match, so only rows with3
values ofMMULT
will be considered.Here the result in case of filters have the value

ALL
:Here the solution when

ALL
token is not used:Note: The only difference with expected result and @player0 solution is that it returns
0
when there is no match.