Search code examples
google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-querysumifs

Arrayformula works for countifs but not sumifs?


Was curious why Formula 2 (below) doesn't work, i.e. returns just a zero and not an array whereas Formula 1 works (below). The argument construction seems is similar.

DM:DM is list of employers. (not unique employers, i.e. Bob post several jobs) DW:DW is # of positions offered for a particular job. DU:DU is type of job.

DM      DW  DU
Bob     3   Sales
Alice   10  Cashier
Mike    4   Clerk 
Bob     1   Sales

I think the issue is the way I am using the "Unique" function nested inside countifs vs. sumifs and wrapping this inside an arrayformula. In Formula 1, the array returns number of job posts for unique employer, and so Bob 2, Alice 1, Mike 1. What I was attempting in Formula 2 was Bob 4, Alice 10, Mike 4. I could accomplish this by separating multiple columns and functions but I wondered if anyone knew of an elegant way to do this using arrayformula so I have it in one column. Thanks and I hope this question was clear.

Formula 1

=arrayformula(countifs('Data (QC)'!DM:DM,UNIQUE('Data (QC)'!DM:DM),'Data (QC)'!DU:DU,"Shop Sales Assistant"))

Formula 2

=arrayformula(sumifs('Data (QC)'!DW:DW,'Data (QC)'!DM:DM,unique('Data (QC)'!DM:DM),'Data (QC)'!DU:DU,"Shop Sales Assistant"))

Solution

  • =arrayformula ( unique ({filter( Log!M2:M, Log!M2:M<>"" ), sumif ( filter ( Log!M2:M, Log!M2:M<>"" ), "=" & filter ( Log!M2:M, Log!M2:M<>"" ), Log!W2:W )}))