Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ndel40
 
Posts: n/a
Default Sumproduct on filtered cells

How can I use the following SUMPRODUCT formula that counts only unique
records on filter list?

=SUMPRODUCT(($A$2:$A$20<"")/(COUNTIF($A$2:$A$20,$A$2:$A$20)+($A$2:$A$20="")))

The formula works fine on the list until I filter the data. I would like to
have the formula update based on the filtered data.

For example:

Unfiltered list:
Unfiltered result = 3
Data
1
1
1
2
2
3
3

Filtered list, which displays only 1 & 2:
Desired filtered result = 2
Data
1
1
1
2
2

Thanks,

Nick





  #2   Report Post  
Domenic
 
Posts: n/a
Default


=SUM(IF((A2:A20<"")*(SUBTOTAL(9,OFFSET(A2,ROW(A2: A20)-ROW(A2),0))),1/COUNTIF(A2:A20,A2:A20)))

...entered using CONTROL+SHIFT+ENTER.

Hop this helps!


--
Domenic
------------------------------------------------------------------------
Domenic's Profile: http://www.excelforum.com/member.php...o&userid=10785
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #3   Report Post  
Aladin Akyurek
 
Posts: n/a
Default


Assuming that A2:A20 consists of numbers as your sample suggests...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2: A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2: A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))

which must be confirmed with control+shift+enter instead of just with
enter.

Ndel40 Wrote:
How can I use the following SUMPRODUCT formula that counts only unique
records on filter list?

=SUMPRODUCT(($A$2:$A$20<"")/(COUNTIF($A$2:$A$20,$A$2:$A$20)+($A$2:$A$20="")))

The formula works fine on the list until I filter the data. I would
like to
have the formula update based on the filtered data.

For example:

Unfiltered list:
Unfiltered result = 3
Data
1
1
1
2
2
3
3

Filtered list, which displays only 1 & 2:
Desired filtered result = 2
Data
1
1
1
2
2

Thanks,

Nick



--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #4   Report Post  
Domenic
 
Posts: n/a
Default


Aladin Akyurek Wrote:
Assuming that A2:A20 consists of numbers as your sample suggests...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2: A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2: A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))

which must be confirmed with control+shift+enter instead of just with
enter.


Is there an advantage in using this formula instead of the one I
offered?


--
Domenic
------------------------------------------------------------------------
Domenic's Profile: http://www.excelforum.com/member.php...o&userid=10785
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #5   Report Post  
Ndel40
 
Posts: n/a
Default

I used:

=SUM(IF((A2:A20<"")*(SUBTOTAL(9,OFFSET(A2,ROW(A2: A20)-ROW(A2),0))),1/COUNTIF(A2:A20,A2:A20)))

It works perfect!!!

Thanks!

"Domenic" wrote:


Aladin Akyurek Wrote:
Assuming that A2:A20 consists of numbers as your sample suggests...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2: A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2: A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))

which must be confirmed with control+shift+enter instead of just with
enter.


Is there an advantage in using this formula instead of the one I
offered?


--
Domenic
------------------------------------------------------------------------
Domenic's Profile: http://www.excelforum.com/member.php...o&userid=10785
View this thread: http://www.excelforum.com/showthread...hreadid=273885




  #6   Report Post  
Aladin Akyurek
 
Posts: n/a
Default


Domenic Wrote:
Is there an advantage in using this formula instead of the one I
offered?


Domenic,

That formula as such won't work. Consider:

Data Code
1 x
1 x
2 x
2 y
3 y
3 y

Filter for Code = x. The result that you'll get will be: 1.5 instead of
2.


--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #7   Report Post  
Domenic
 
Posts: n/a
Default


Yep! It looks like I didn't test it fully. As far as your formula...I
think for now I'll go cower in some corner. :)

Thanks Aladin!

Aladin Akyurek Wrote:
Domenic,

That formula as such won't work. Consider:

Data Code
1 x
1 x
2 x
2 y
3 y
3 y

Filter for Code = x. The result that you'll get will be: 1.5 instead of
2.



--
Domenic
------------------------------------------------------------------------
Domenic's Profile: http://www.excelforum.com/member.php...o&userid=10785
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #8   Report Post  
Ndel40
 
Posts: n/a
Default

I updated my spreadsheet to use Aladin's formula. It works great... although
I'm not sure how the formula works. I always seek to understand and I'm
interested in an explanation if you could please oblige.

Thanks,

Nick


"Domenic" wrote:


Yep! It looks like I didn't test it fully. As far as your formula...I
think for now I'll go cower in some corner. :)

Thanks Aladin!

Aladin Akyurek Wrote:
Domenic,

That formula as such won't work. Consider:

Data Code
1 x
1 x
2 x
2 y
3 y
3 y

Filter for Code = x. The result that you'll get will be: 1.5 instead of
2.



--
Domenic
------------------------------------------------------------------------
Domenic's Profile: http://www.excelforum.com/member.php...o&userid=10785
View this thread: http://www.excelforum.com/showthread...hreadid=273885


  #9   Report Post  
Aladin Akyurek
 
Posts: n/a
Default


Nick,

The formula combines two tracks...

1.

SUM(IF(FREQUENCY(NumRange,NumRange)0,1))

where the FREQUENCY(NumRange,NumRange) bit determines frequencies for
the distinct members of NumRange which also serve as an array of bins.
The wrapping IF maps all non-zero frequencies to 1's which the outer
SUM totals. The end result is a count of distinct numbers in NumRange.

2.

SUBTOTAL(3,OFFSET(Range,ROW(Range)-MIN(ROW(Range)),,1))

which is due to Longre is described he

http://j-walk.com/ss/excel/eee/eee001.txt

It produces an array of 1's and 0's which stand for filtered and
unfiltered: 1 corresponds to a row that's visible, 0 to a row that's
invisble.

These two combined...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2:
A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2:
A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))


allows us to consider just the numbers that are in the visible set.

Ndel40 Wrote:
I updated my spreadsheet to use Aladin's formula. It works great...
although
I'm not sure how the formula works. I always seek to understand and
I'm
interested in an explanation if you could please oblige.
[...]



--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #10   Report Post  
Ndel40
 
Posts: n/a
Default

Now I understand!

Thanks!

"Aladin Akyurek" wrote:


Nick,

The formula combines two tracks...

1.

SUM(IF(FREQUENCY(NumRange,NumRange)0,1))

where the FREQUENCY(NumRange,NumRange) bit determines frequencies for
the distinct members of NumRange which also serve as an array of bins.
The wrapping IF maps all non-zero frequencies to 1's which the outer
SUM totals. The end result is a count of distinct numbers in NumRange.

2.

SUBTOTAL(3,OFFSET(Range,ROW(Range)-MIN(ROW(Range)),,1))

which is due to Longre is described he

http://j-walk.com/ss/excel/eee/eee001.txt

It produces an array of 1's and 0's which stand for filtered and
unfiltered: 1 corresponds to a row that's visible, 0 to a row that's
invisble.

These two combined...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2:
A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2:
A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))


allows us to consider just the numbers that are in the visible set.

Ndel40 Wrote:
I updated my spreadsheet to use Aladin's formula. It works great...
although
I'm not sure how the formula works. I always seek to understand and
I'm
interested in an explanation if you could please oblige.
[...]



--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885




  #11   Report Post  
Ndel40
 
Posts: n/a
Default

Aladin,

The formula works well when counting numbers, but it returns #N/A when I try
to count text.

Can the formula be modified to count text?

Thanks,

Nick

"Ndel40" wrote:

Now I understand!

Thanks!

"Aladin Akyurek" wrote:


Nick,

The formula combines two tracks...

1.

SUM(IF(FREQUENCY(NumRange,NumRange)0,1))

where the FREQUENCY(NumRange,NumRange) bit determines frequencies for
the distinct members of NumRange which also serve as an array of bins.
The wrapping IF maps all non-zero frequencies to 1's which the outer
SUM totals. The end result is a count of distinct numbers in NumRange.

2.

SUBTOTAL(3,OFFSET(Range,ROW(Range)-MIN(ROW(Range)),,1))

which is due to Longre is described he

http://j-walk.com/ss/excel/eee/eee001.txt

It produces an array of 1's and 0's which stand for filtered and
unfiltered: 1 corresponds to a row that's visible, 0 to a row that's
invisble.

These two combined...

=SUM(IF(FREQUENCY(SUBTOTAL(3,OFFSET(A2:A20,ROW(A2:
A20)-MIN(ROW(A2:A20)),,1))*A2:A20,SUBTOTAL(3,OFFSET(A2:
A20,ROW(A2:A20)-MIN(ROW(A2:A20)),,1))*A2:A20)0,1))-(SUBTOTAL(3,A2:A20)<COUNTA(A2:A20))


allows us to consider just the numbers that are in the visible set.

Ndel40 Wrote:
I updated my spreadsheet to use Aladin's formula. It works great...
although
I'm not sure how the formula works. I always seek to understand and
I'm
interested in an explanation if you could please oblige.
[...]



--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885


  #12   Report Post  
Daniel.M
 
Posts: n/a
Default

Hi,

The formula works well when counting numbers, but it returns #N/A when I try
to count text.


=SUM(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),--(MMULT((A2:A20=TRANSPOSE
(A2:A20))*TRANSPOSE(SUBTOTAL(3,OFFSET(A2,ROW(A2:A2 0)-ROW(A2),,1)))*(ROW(A2:A20)
=TRANSPOSE(ROW(A2:A20))),ROW(A2:A20)^0)=1)))

Regards,

Daniel M.


  #13   Report Post  
Ndel40
 
Posts: n/a
Default

That worked great!

Thanks,

Nick

"Daniel.M" wrote:

Hi,

The formula works well when counting numbers, but it returns #N/A when I try
to count text.


=SUM(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),--(MMULT((A2:A20=TRANSPOSE
(A2:A20))*TRANSPOSE(SUBTOTAL(3,OFFSET(A2,ROW(A2:A2 0)-ROW(A2),,1)))*(ROW(A2:A20)
=TRANSPOSE(ROW(A2:A20))),ROW(A2:A20)^0)=1)))

Regards,

Daniel M.



  #14   Report Post  
Daniel.M
 
Posts: n/a
Default

You're welcome.

You may also try this one (also an ARRAY formula):

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20)))-1)0))

Regards,

Daniel M.

"Ndel40" wrote in message
...
That worked great!

Thanks,

Nick



  #15   Report Post  
Daniel.M
 
Posts: n/a
Default

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20)))-1)0))


The -1 is not required (it puts the 0 count at the resulting array's beginning
instead of at the end). So :

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20))))0))

You can even 'count unique' on more criterias OUTSIDE of the filtered list (if
you see fit), as in:

=SUM(--(FREQUENCY(IF(SUBTOTAL(...)*(cond2)*(cond3),MATCH( ...)),ROW(...))0))

Regards,

Daniel M.




  #16   Report Post  
Aladin Akyurek
 
Posts: n/a
Default


A credit-deserving contribution.

Daniel.M Wrote:
=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20)))-1)0))


The -1 is not required (it puts the 0 count at the resulting array's
beginning
instead of at the end). So :

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20))))0))

You can even 'count unique' on more criterias OUTSIDE of the filtered
list (if
you see fit), as in:

=SUM(--(FREQUENCY(IF(SUBTOTAL(...)*(cond2)*(cond3),MATCH( ...)),ROW(...))0))

Regards,

Daniel M.



--
Aladin Akyurek
------------------------------------------------------------------------
Aladin Akyurek's Profile: http://www.excelforum.com/member.php...fo&userid=4165
View this thread: http://www.excelforum.com/showthread...hreadid=273885

  #17   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi Daniel

just as an alternatve (very similar of course :-))
=COUNT(1/FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),MAT
CH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2:A20 )))))


--
Regards
Frank Kabel
Frankfurt, Germany


Daniel.M wrote:
=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20)))-1)0))


The -1 is not required (it puts the 0 count at the resulting array's
beginning instead of at the end). So :

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20))))0))

You can even 'count unique' on more criterias OUTSIDE of the filtered
list (if you see fit), as in:


=SUM(--(FREQUENCY(IF(SUBTOTAL(...)*(cond2)*(cond3),MATCH( ...)),ROW(...)
)0))

Regards,

Daniel M.


  #18   Report Post  
Daniel.M
 
Posts: n/a
Default

Thanks Aladin :-)


  #19   Report Post  
Daniel.M
 
Posts: n/a
Default

Hi Frank,

just as an alternatve (very similar of course :-))
=COUNT(1/FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),MAT
CH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2:A20 )))))



Yep. Nick has indeed many choices :-)

Regards,

Daniel M.


  #20   Report Post  
Ndel40
 
Posts: n/a
Default

This version worked great and is much faster than the other formula!

Thanks,

Nick

"Daniel.M" wrote:

You're welcome.

You may also try this one (also an ARRAY formula):

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A2,ROW(A2:A20)-ROW(A2),,1)),
MATCH(A2:A20,A2:A20,0)),ROW(INDIRECT("1:"&ROWS(A2: A20)))-1)0))

Regards,

Daniel M.

"Ndel40" wrote in message
...
That worked great!

Thanks,

Nick




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Heps to design Locked/Unlocked cells in protected worksheet Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:09 AM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM
Sumproduct ... Empty Cells vs Spaces? Ken Excel Discussion (Misc queries) 9 December 17th 04 08:03 PM
Pasting onto filtered cells Mediaexcel Excel Worksheet Functions 1 October 27th 04 10:29 PM
Pasting onto filtered cells Mediaexcel Excel Worksheet Functions 1 October 27th 04 05:44 PM


All times are GMT +1. The time now is 10:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"