Dynamic count depending on matching / non-matching criteria

ellison

Active Member
Joined
Aug 1, 2012
Messages
337
Office Version
  1. 365
Platform
  1. Windows
Hi, we have to collate reports from different departments. And I've been asked if we can help sort out (an evergrowing!) snag.


There is a list of info
Customer NameOrders
PETER SMITHABC123
david jones5962-99-3
peter smithXYZ789
222246Green Bottles
David Jones
David Jones5962-99-3
Peter Smith_02abc123

<tbody>
</tbody>


What we are looking to do is add a third field in Col C which tell us how many *different* outcomes there are for each entry in Col A.
i.e.
Peter Smith: 2 different product codes. (no need to list them, just show the number of them).
222246: 1 product code
David Jones 1 product code (a blank wouldn't count as an order code)
Peter Smith_02: 1 product code

I think we could maybe do this via a pivot table (but pivot tables as well as macros have been vetoed by the powers-that-be!).

I've been looking into adding a helper column and concatenating some info together, naming table ranges, trying different functions such as if / whatifs / countifs and a few other things, but I just can't figure it out.

The complications we have are that:
- it needs to be a dynamic count so that if an entry is edited, that gets reflected straight away in the results
- the data in Col A Col B can be in text (upper or lower case) or numeric, or a mix of both
- col B can sometimes be blanks
- I can't ask for the way I receive the info to be changed, grr!


Hoping somebody may be able to point me in the right direction?!

~With many thanks~

Neil
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Neil,

You *can* do it with a pivot table, it's quicker and faster than working out a specific formula for this.

This may give you a start but it won't do all that you are asking for:
Code:
=SUMPRODUCT(--($A$2:$A$8=A2),--(LEN($B$2:$B$8)>0))

Other steps to aid:
- Delete rows where column B is blank
- Sort rows by column A
- Copy Column A to column C and use Date -> Remove Duplicates
- Column D you can use above formula (cell ranges adjusted) or COUNTIF function to then count the reduced data (reduced assumes you did delete blank rows) in columns A:B with results against the unique list in column C
 
Last edited:
Upvote 0
Thanks all the same Jack, but I seem to be pretty far away from where I need to be.
Appreciated though!
 
Upvote 0
On the plus side, I could put on a pivot table and then do a vlookup column next to the raw data to show the different pivot table counts.
BUT
I think the reason this has been vetoed in the past is that the pivot table counts aren't "live". i.e. if somebody deletes some raw data, then the pivot table has to be refreshed before the change in "count" will be shown.

I'm still scratching my head, argghhhhhhhhhhh
 
Upvote 0
You're complaint is clicking Refresh vs figuring out some dynamic updating formula given the pivot table probably would have achieved this by now and your powers that be could be analysing results vs waiting for them..? ;)
 
Upvote 0
Thanks again Patrick.
I think the main issue is that this will end up being used on a shared file.
As a result, a dynamic updating formula would be huge bonus.
Best
Neil
 
Upvote 0

Book1
ABC
1Customer NameOrdersD-Count
2PETER SMITHABC1232
3david jones5962-99-31
4peter smithXYZ7892
5222246Green Bottles1
6David Jones1
7David Jones5962-99-31
8Peter Smith_02abc1231
Sheet1


In Formulas | Name Manager:

1. Define Lrow as referring to...

=MATCH(REPT("z",255),Sheet1!$B:$B)

2. Define Cus as referring to...

=Sheet1!$A$2:INDEX(Sheet1!$A:$A,Lrow)

3. Define Order as referring to:

=Sheet1!$B$2:INDEX(Sheet1!$B:$B,Lrow)

4. Define Ivec (from integer vector) as referring to:

=ROW(Order)-ROW(INDEX(Order,1,1))+1

5. Now in C2 control+shift+enter, not just enter, and copy down:

=IFERROR(VLOOKUP($A2,$A$1:$C1,3,0),SUM(IF(FREQUENCY(IF(Order<>"",IF(Cus=$A2,MATCH(Order,Order,0))),Ivec),1)))

Replace IFERROR with IFNA if available on your system.

Note. I did not profile whether implementing just the counting part, i.e.

=SUM(IF(FREQUENCY(IF(Order<>"",IF(Cus=$A2,MATCH(Order,Order,0))),Ivec),1))

instead of implementing look up + counting as suggested in [5].
 
Upvote 0
Wow, that is PERFECT - and quite astonishingly good!

I'd reckon you are to Excel what Elvis is to music: THE KING :)

With many thanks indeed

Neil
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,757
Members
448,991
Latest member
Hanakoro

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