Hi guy,
Looks like Carim was kind enough to supply the answers. I will supply the explanation. I will use the easiest one for the explanation ...
You can either follow along mentally or actually put it into your workbook.
I am using the file “Payroll G.xls”. The first thing I will do is to calculate the results for cell C3 on the PayPeriod sheet. I will do this by using 4 blanks columns on the Master sheet, columns M, N, O, and P
In cell M3, I put this formula:
=A3=PayPeriod!$A$3
and drag it down. This compares each of the sales reps initials with the initials in cell A3 on the PayPeriod sheet and returns a series of TRUE and FALSE.
To convert these into numeric results, we multiply by 1:
=(A3=PayPeriod!$A$3)*1
Multiplying TRUE by 1 gives 1; multiplying FALSE by 1 gives 0.
For debatable reasons, people prefer to use this instead of multiplying by 1:
=--(A3=PayPeriod!$A$3)
Using similar logic, I put the following formulas in cells N3 and O3
=--(B3>=PayPeriod!$E$1)
=--(B3<=PayPeriod!$G$1)
and drag them down. These formulas compare the dates in column B with the pay period start and end dates, and return TRUE or FALSE, then multiply the result by 1 (or by -1 twice) to get numeric results of 1 and 0.
We want to identify those rows which meet all 3 criteria:
1. sales rep’s initials match the initials in PayPeriod cell A3
2. date of sale is on or after the beginning of the PayPeriod
3. date of sales is on or before the end of the PayPeriod
To determine which rows meet all 3 criteria, we can multiply together the results for each of the 3 criteria, by putting this formula in cell P3:
=M3*N3*O3
and dragging down.
To count the number of rows where all 3 criteria are met, we sum up column P. I put this formula in cell M2:
=SUM(P:P)
There is an obvious problem with using this approach. It required 4 columns to get the results for a single cell. So, how to simplify this?
First, I can replace the formula in cell M2 with SUMPRODUCT:
=SUMPRODUCT(M3:M28,N3:N28,O3:O28)
The function SUMPRODUCT does the combination of what we did in column P, and it also does the SUM we used in cell M2. Namely, it multiplies M3*N3*O3, and adds that to M4*N4*O4, et cetera.
The next thing we can do is replace each of these cell references with the formulas that produced them. Doing this one at a time, we get:
=SUMPRODUCT(M3:M28,N3:N28,O3:O28)
=SUMPRODUCT(--(A3:A28=PayPeriod!$A$3),N3:N28,O3:O28)
=SUMPRODUCT(--(A3:A28=PayPeriod!$A$3),--(B3:B28>=PayPeriod!$E$1),O3:O28)
=SUMPRODUCT(--(A3:A28=PayPeriod!$A$3),--(B3:B28>=PayPeriod!$E$1),--(B3:B28<=PayPeriod!$G$1))
To be able to take this formula and put it on the PayPeriod sheet (and be able to drag it down that sheet’s column C without a problem) we need to change the references.
=SUMPRODUCT(--(Master!$A$3:$A$28=PayPeriod!$A3),--(Master!$B$3:$B$28>=PayPeriod!$E$1),--(Master!$B$3:$B$28<=PayPeriod!$G$1))
Bookmarks