# Summing data based on multiple criteria - Dynamic formula option?

Occasional Contributor

# Summing data based on multiple criteria - Dynamic formula option?

Attached is a two tab data set representative of a problem I run into frequently.

* The "Payroll Source" tab has financial information listed monthly in consecutive columns (i.e. 12 months = 12 columns).

* On the "Payroll by division" tab, I'm trying to break out the monthly data by Department and Division, ultimately needing to take what is 1 column in the source data and "allocate" it across rows/ columns based on Department / Division criteria in the respective month.

* The main thing I'm trying to solve for is how to create a dynamic formula that allows me to take 12 columns of monthly data from the source tab and "spread" it across 48 columns (4 divisions per month) without having to change the sum range for each new month.

I've currently populated the Payroll by Division tab using SUMIFS but that still requires me manually adjusting/changing the Sum Range within that formula whenever a new month starts.

How can I change this formula (or use a different one altogether?) that also checks the month on the source tab so that I could basically create the formula in Jan21 of the "Payroll by Division" tab and drag across the rest of the months without having to manually change the Sum Range at the "beginning" of each new month? My first thought is to always add a third criteria - the month - but it's my understanding that the SUMIFS formula can't include row and column criteria, only one or the other. Is that correct?

2 Replies

# Re: Summing data based on multiple criteria - Dynamic formula option?

In D13 on the Payroll by Division sheet:

=SUMPRODUCT('Payroll source'!\$G\$13:\$R\$167,('Payroll source'!\$D\$13:\$D\$167=\$C13)*('Payroll source'!\$E\$13:\$E\$167=D\$12)*('Payroll source'!\$G\$3:\$R\$3=INDEX(\$11:\$11,4*QUOTIENT(COLUMN(D\$5),4))))

Fill down, then to the right (or vice versa)

In BA13:

=SUMPRODUCT('Payroll source'!\$G\$13:\$R\$167,('Payroll source'!\$D\$13:\$D\$167=\$C13)*('Payroll source'!\$E\$13:\$E\$167=D\$12)*('Payroll source'!\$G\$2:\$R\$2=INDEX(\$11:\$11,4*QUOTIENT(COLUMN(BA\$5)-1,4)+1)))

Fill down, then to the right (or vice versa)

# Re: Summing data based on multiple criteria - Dynamic formula option?

I got as far as returning a 5x4 spilt range for each date.

= LET(
source, XLOOKUP(@DateHdr,SourceDate,sourceData),
SUMIFS(source,Department,DeptHdr,Division,DivHdr))

As things stand, the formula would need to by copied 12 times.  My goal would be to return the entire result as a single array formula but, even with the new Lambda functions, stitching the results together is likely to be a cumbersome process.