Calculate average in (for me) difficult sumproduct formula

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
233
Office Version
  1. 2016
Platform
  1. Windows
Hello all,

I use the following formule to count "x" in column F based on the month.

=SUMPRODUCT((G$3:G$10>=A3)*(G$3:G$10<=EOMONTH(A3;0))*(F$3:F$10="x"))

Column F is "x" when a file is send retour. Column H shows "x" when the the retour is returned. Both with corresponding dates.
Now i would like to calculate the average day it takes before a retour is returned.

I made this test file. I don't see why the Returned column is counting the returns. It works in my "real" file

Book1
ABCDEFGHI
12022
2MonthReturnedAverage time [days] between A and BAB
3January0x28-sep-22x30-sep-22
4February0x30-sep-22x4-okt-22
5March0x28-sep-22x3-okt-22
6April0x30-sep-22x30-sep-22
7May0x4-okt-22x4-okt-22
8June0x6-okt-22x6-okt-22
9July0x6-okt-22x14-okt-22
10August0x1-okt-22x11-okt-22
11September0
12October0
13November0
14December0
Sheet1
Cell Formulas
RangeFormula
A3:A14A3=DATE($C$1,ROWS($1:1),1)
B3:B14B3=SUMPRODUCT((G$3:G$10>=A3)*(G$3:G$10<=EOMONTH(A3,0))*(F$3:F$10="x"))
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I made this test file. I don't see why the Returned column is counting the returns.

Is it because your formula returning the months in column B is expecting the year to be in C3 and not A1?

I use the following formule

Is there a reason you are not using COUNTIFS() rather that SUMPRODUCT()?

Now i would like to calculate the average day it takes before a retour is returned.

Book1
ABCDEFGHIJ
12022
2MonthReturnedAverage time [days] between A and BABB less A
301/01/20220 x28/09/2022x30/09/20222
401/02/20220 x30/09/2022x04/10/20224
501/03/20220 x28/09/2022x03/10/20225
601/04/20220 x30/09/2022x30/09/20220
701/05/20220 x04/10/2022x04/10/20220
801/06/20220 x06/10/2022x06/10/20220
901/07/20220 x06/10/2022x14/10/20228
1001/08/20220 x01/10/2022x11/10/202210
1101/09/202242.75
1201/10/202244.5
1301/11/20220 
1401/12/20220 
Sheet1
Cell Formulas
RangeFormula
A3:A14A3=DATE($C$1,ROWS($1:1),1)
B3:B14B3=COUNTIFS(G:G,">="&A3,G:G,"<="&EOMONTH(A3,0),H:H,"x")
C3:C14C3=IFERROR(AVERAGEIFS(J:J,G:G,">="&A3,G:G,"<="&EOMONTH(A3,0),F:F,"x"),"")
J3:J10J3=I3-G3
 
Upvote 0
Solution
I use sumproduct because the data is pulled from an external worksheet
With countifs i found myself looking at #NA or something each time i opened the file and the external file wasn't open.

On my way home i thought already the helper column.
But is it possible without this helper column?

The data in my external file is rather big and very slow and not as clear as my example.
Not sure if i add alot of helper columns the data in the external file will be even slower.
 
Upvote 0
I use sumproduct because the data is pulled from an external worksheet
That's a good enough reason, and if a requirement, then probably worth mentioning at the outset.

The data in my external file is rather big and very slow

Not sure if i add alot of helper columns the data in the external file will be even slower

Using helper columns will almost certainly help to improve speed and performance rather than hinder it.
 
Upvote 0
I thought this was the solution but..

The data is in some other worksheet. When this sheet isn't opened the formula will show 0.
When i open the other worksheet the correct data shows.

I had same problem with =COUNTIFS and i use now SUMPRODUCT to keep data when the other worksheet is closed.

Is there some way to do the same with this formula?
Excel Formula:
=IFERROR(AVERAGEIFS('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$J:$J,'\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G:$G">="&A3,'\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G:$G,"<="&EOMONTH(A3,0),'\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$F:$F,"x"),"")

So the data stays up to date even when the other worksheet is closed
 
Upvote 0
Hi, you'll need to use SUMPRODUCT() to get a conditional SUM and COUNT and divide them.

You'll want to restrict the number of rows used to a sensible maximum for performance reasons - I've used a 1000 rows here.

This is not tested in the slightest - but if not quite right, it hopefully points you in the right direction.

Excel Formula:
=IFERROR(SUMPRODUCT('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$J1:$J1000,--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G1:$G1000>=A3),--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G1:$G1000<=EOMONTH(A3,0)),--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$F1:$F1000="x"))/SUMPRODUCT(--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G1:$G1000>=A3),--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$G1:$G1000<=EOMONTH(A3,0)),--('\\nltilnetapsnas1\data\[Tracker.xlsm]Tracker1'!$F1:$F1000="x")),"")
 
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top