COUNTIF - Avoiding duplicates

arthuro2021

New Member
Joined
Sep 23, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm currently trying to sum a dataset that has duplicates due to a upstream data issue. I cannot get the 'unique' function to work for me. In the attached screen shot I can show you the current formula I have applied in cell H9. The problem with my result is that I'm summing the results twice. How do I add in a criteria to only sum up the items shown in column D once. E.g. per my current formula structure the item in column D '278. - Ent 671 Bank (WBC)' is being included in my sum formula twice for the category in column C 'WIB' as it appears on two lines. I need the formula to only report the value once against category 'WIB' instead of twice because its on two lines. How can I add this criteria into my formula?
 

Attachments

  • Excel Sum Issue with Duplicates.PNG
    Excel Sum Issue with Duplicates.PNG
    88.7 KB · Views: 25

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I would recommend not using whole column references in a formula like that. For example, you are asking Excel to check over a million cells in column C in case they contain the H7 value. Just choose a range that will surely be big enough to cover any data that you are likely to have.

See if something like this does what you want.

Excel Formula:
=SUM(UNIQUE(FILTER(D8:E1000,(B8:B1000=H6)*ISNUMBER(SEARCH(H7,C8:C1000)),0)))
 
Upvote 0
Hi, the sum formula worked great. thankyou. I also need to count the number of unique records and I tried adjusting the formula and ranges but the results are not correct. Would be be able to advise what I have done wrong from the attached screenshot?
 

Attachments

  • Excel Count Issue with Duplicates.PNG
    Excel Count Issue with Duplicates.PNG
    86.9 KB · Views: 6
Upvote 0
Bit hard to tell for sure from an image as we cannot test with that but since column D contains text, not numbers, COUNT would not work on that column.
Try replacing the COUNT function with the ROWS function.

If that does not work, can you copy/paste values from that worksheet to the same cells in a blank worksheet and post a mini-sheet here using XL2BB and also tell us what answer you expect and why?

BTW, good to see that you have restricted the row ranges in your attempted formula. (y)
 
Upvote 0
Hi, tried the function ROWS and that worked for the rows with a value to count but returned a 1 for items that should be 0. Strange.
Have uploaded the spreadsheet with my attempt as requested.

Count Formula Issue.xlsx
ABCDEFGHIJKL
1Legal Entity(Multiple Items)
2Line of Business(All)
3Counterparty Line of Business(All)
4Reporting Classification>= 1M AND <10M
5
6Sum of Actual YTDTotal SumTotal Count
7Account ClassificationFinancialStatement_IGJoin LOBTagTag Actual Balance YTDTotalBalance Sheet _>= 1M AND <10MBalance Sheet _>= 1M AND <10MExpected Result
8Balance Sheet Balance Sheet _>= 1M AND <10MNZ BankingNZ Banking4301. - 582 vs588 entity1,283,5751,283,575Specialist Businesses- 7,718,15144TRUE
9Balance Sheet _>= 1M AND <10MSpecialist BusinessesWIB278. - Ent 671 Bank (WBC)- 7,444,95315,471,831Business Bank-10FALSE
10Balance Sheet _>= 1M AND <10MSpecialist BusinessesWIB3488. - SGML Bank account - (SGB)5,630,96327,641,552Consolidation-10FALSE
11Balance Sheet _>= 1M AND <10MSpecialist BusinessesWIB3618. - AUD Nostro/Vostro between Pacific Banking and WBC Sydney- 3,046,6168,002,196Consumer Bank-10FALSE
12Balance Sheet _>= 1M AND <10MSpecialist BusinessesWIB374. - WLIS Cash balances- 2,857,54517,406,212Group Business Unit-10FALSE
13Balance Sheet _>= 1M AND <10MTreasury & Structured FinanceWIB3281. - Offshore Nostro accounts held by NY- 6,656,414613,292Chief Operating Office-10FALSE
14Balance Sheet _>= 1M AND <10MWIBNZ Banking25. - Nostro/Vostro between NZ Wellington (Vostro) and WBC Sydney (Nostro). Variance relates to timing difference.- 1,492,25740,618,625Treasury & Structured Finance- 6,656,41411TRUE
15Balance Sheet _>= 1M AND <10MWIBNZ Banking3940. - Calypso v Midas NZD B/S8,376,17550,258,196WIB- 7,490,64677TRUE
16Balance Sheet _>= 1M AND <10MWIBSpecialist Businesses278. - Ent 671 Bank (WBC)- 7,444,953- 22,916,784NZ Banking8,167,49433TRUE
17Balance Sheet _>= 1M AND <10MWIBSpecialist Businesses3488. - SGML Bank account - (SGB)5,630,963- 22,010,589
18Balance Sheet _>= 1M AND <10MWIBSpecialist Businesses3618. - AUD Nostro/Vostro between Pacific Banking and WBC Sydney- 3,046,616- 11,048,812
19Balance Sheet _>= 1M AND <10MWIBSpecialist Businesses374. - WLIS Cash balances- 2,857,545- 20,263,757 =COUNT(UNIQUE(FILTER(D$8:D$1000,(B$8:B$1000=$J$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),0)))
20Balance Sheet _>= 1M AND <10MWIBTreasury & Structured Finance3281. - Offshore Nostro accounts held by NY- 6,656,414- 7,269,706 =ROWS(UNIQUE(FILTER(D$8:D$1000,(B$8:B$1000=$J$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),0)))
21Balance Sheet _>= 1M AND <10MWIBWIB25. - Nostro/Vostro between NZ Wellington (Vostro) and WBC Sydney (Nostro). Variance relates to timing difference.- 1,492,257- 42,110,882
22Balance Sheet _>= 1M AND <10MWIBWIB3940. - Calypso v Midas NZD B/S8,376,175- 41,882,021
23Profit and LossProfit and Loss_>= 1M AND <10MNZ BankingNZ Banking467. - NZ Incorporations- 1,318,679- 1,318,679
24Profit and Loss_>= 1M AND <10MWIBWIB4711. - SYD and WLG translation diffs 213017 vs 2050971,898,0751,898,075
25Grand Total- 5,627,675
Sheet1 IG
Cell Formulas
RangeFormula
I8:I16I8=SUM(UNIQUE(FILTER(D$8:E$1000,(B$8:B$1000=$I$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),0)))
J8:J16J8=ROWS(UNIQUE(FILTER(D$8:D$1000,(B$8:B$1000=$J$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),0)))
L8:L16L8=K8=J8
 
Upvote 0
OK, I wasn't sure if you would have any zero counts. Try this instead

Excel Formula:
=IFNA(ROWS(UNIQUE(FILTER(D$8:D$1000,(B$8:B$1000=$J$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),NA()))),0)
 
Upvote 0
Solution
OK, I wasn't sure if you would have any zero counts. Try this instead

Excel Formula:
=IFNA(ROWS(UNIQUE(FILTER(D$8:D$1000,(B$8:B$1000=$J$7)*ISNUMBER(SEARCH(H8,C$8:C$1000)),NA()))),0)
yes it worked, fantastic stuff Peter_SSs. Thankyou and have a great weekend!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,541
Messages
6,125,413
Members
449,223
Latest member
Narrian

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