Sumproduct equivalent for Aggregate dealing with #VALUE results in column

Poenankie

New Member
Joined
Aug 23, 2013
Messages
12
How would one write a formula to do what, for example, =AGGREGATE(1,7,NovDataTable[Inc Closed Date - Inc Date]) does?

I have a data table called NovDataTable and want a formula to get the average values in the table column [Inc Closed Date - Inc Date], without resorting to the aggregate function or filtering out #VALUE! values.

Can this be done, maybe with Sumproduct and Subtotal? I was unable to achieve the required result and always end up with "#VALUE!" as a result.

Thank you

Kind regards,
Poenankie
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
AGGREGATE really is very good in those situations!

Without, I think you'll need to use an array formula**:

=AVERAGE(IF(SUBTOTAL(102,OFFSET(INDEX(NovDataTable[Inc Closed Date - Inc Date],1),ROW(NovDataTable[Inc Closed Date - Inc Date])-MIN(ROW(NovDataTable[Inc Closed Date - Inc Date])),)),NovDataTable[Inc Closed Date - Inc Date]))

Regards


**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
 
Last edited:
Upvote 0
You could use a helper column to do the subtotal bit
I'll use example with regular ranges instead of named ranges.

You want to average A1:A100, but ignore #Value! errors.

In B1 and filled down to B100
=SUBTOTAL(102,A1)

Then use
=AVERAGEIF(B1:B100,1,A1:A100)
 
Upvote 0
@XOR LX:
Thank you very much, it is working beautifully!

Would you mind explaining how it works please?

=AVERAGE(IF(SUBTOTAL(102,OFFSET(INDEX(NovDataTable[Inc Closed Date - Inc Date],1),ROW(NovDataTable[Inc Closed Date - Inc Date])-MIN(ROW(NovDataTable[Inc Closed Date - Inc Date])),)),NovDataTable[Inc Closed Date - Inc Date]))

@Jonmo1:

Thank you very much, it is working perfectly, unfortunately it has to be done without a helper column.

I guess it won't be possible to do it with sumproduct then?

Kind regards,
Poenankie
 
Upvote 0
unfortunately it has to be done without a helper column.
Why ?

I find the answer to this more often than not is 'because management says so'.
Well If they prefer a slow sheet with 1 set of formulas, instead of a fast sheet with 2, then ok.
The helper column can be hidden, and it doesn't even have to be on the same sheet.

My reason for preferring the helper column is this
Once you have 1 formula that you want to ignore hidden rows, then you will likely have another, and another.
With the single formula method, Each formula must repeat that subtotal calculation.
With the helper column, the subtotal is done only once, and each formula simply refers to that column.
It's much (MUCH) more efficient.


As an aside,
Maybe you're better off adjusting the source formulas so that they don't return #Value! in the first place.
Then you can just use =SUBTOTAL(1,range)
 
Last edited:
Upvote 0
@XOR LX:
Thank you very much, it is working beautifully!

You're welcome, though it's a shame that you can't employ Jonmo's helper-column set-up, as it is more efficient and also easier to understand.

Would you mind explaining how it works please?

The part:

INDEX(NovDataTable[Inc Closed Date - Inc Date],1)

simply returns, in this case, the range reference for the first cell in the Inc Closed Date - Inc Date column. Let's assume that that is cell A2 for the sake of argument.

In order to use this SUBTOTAL set-up, we must pass an array of range references to that function, which we achieve via the part:

OFFSET(INDEX(NovDataTable[Inc Closed Date - Inc Date],1),ROW(NovDataTable[Inc Closed Date - Inc Date])-MIN(ROW(NovDataTable[Inc Closed Date - Inc Date])),)

which works since the part:

ROW(NovDataTable[Inc Closed Date - Inc Date])-MIN(ROW(NovDataTable[Inc Closed Date - Inc Date]))

will return an array of integers from 0 up to one less the number of rows within that column. For example, if the number of rows within Inc Closed Date - Inc Date were 9, the above would return:

{0;1;2;3;4;5;6;7;8}

Hence, in that case (and recall that we are assuming that the reference of the first cell in that column is A2) the above construction would be equivalent to:

OFFSET(A2,{0;1;2;3;4;5;6;7;8},)

which would return, in this case, an array of cell references, each equivalent to offsetting cell A2 by 0, 1, 2, etc. rows downwards, i.e.:

A2;A3;A4;A5;A6;A7;A8;A9;A10

For example, assuming some random values within those cells, we might have:

{#VALUE!;75;32;#VALUE!;#VALUE!;43;#VALUE!;#VALUE!;#VALUE!}

We then pass this array to SUBTOTAL with an initial parameter of 102, which will return a 1 if that cell is both visible and contains a numeric, and 0 otherwise. Note that #VALUE! is not a numeric.

For example, let's assume that rows 5, 6 and 7 are hidden, then:

SUBTOTAL(102,{#VALUE!;75;32;#VALUE!;#VALUE!;43;#VALUE!;#VALUE!;#VALUE!})

would return:

{0;1;1;0;0;0;0;0;0}

Finally:

=AVERAGE(IF({0;1;1;0;0;0;0;0;0},NovDataTable[Inc Closed Date - Inc Date]))

is the easy part, taking the average of values only where the above array contains a 1.

I guess it won't be possible to do it with sumproduct then?

Not without convolution, no. SUMPRODUCT sums, in general, rather than taking averages.

Regards
 
Upvote 0
@Jonmo1:
What you are saying makes a lot of sense and I will definitely approach future projects with that in mind, thank you very much!

@XOR LX:
Thank you for the succinct explanation, I appreciate it very much!

Kind Regards,
Poenankie
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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