Sum unique values with multiple criteria

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hey all,

I am trying to create a formula in the that only sums the first unique value in column B but I need this sum to include a secondary grouping criteria which is column A (so only sum unique values for the Apple ground and then only sum unique values for orange and so on). I am not quite sure how to add in the the additional logic. I have been testing a combination of SUMPRODUCT, SUMIFS and UNIQUE to no avail.

I have the formula to sum all unique values for all cells using this formula =SUMPRODUCT(1/COUNTIFS(B2$:B$9,B$2:B$9&""),B$2:B$9). This currently gives me a value 381.9 for all cells in C2:C9. I need add a secondary criteria to only sum unique values when column A is the same number which would result in multiple values (361.9, 12 and 8) as shown below.

Can anybody provide a helpful solution to amend the SUMPRODUCT formula?

1654065208355.png


Thanks,
Milos
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
First attempt, though I believe a single cell formula is possible using LET/LAMBDA combo.
Book1
ABCD
1NameProductivitySum Unique ProductivityHelper
2Apple246,3361,91
3Apple30,6361,91
4Apple246,3361,92
5Apple85361,91
6Orange1121
7Orange4121
8Orange7121
9Banana881
Sheet1
Cell Formulas
RangeFormula
C2:C9C2=SUMIFS(B2:B9,A2:A9,A2:A9,D2:D9,1)
D2:D9D2=SUM(--EXACT(A2&B2,$A$2:A2&$B$2:B2))
Dynamic array formulas.
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’).

I have been testing a combination of SUMPRODUCT, SUMIFS and UNIQUE to no avail.
What about this?

22 06 01.xlsm
ABC
2Apple246.3361.9
3Apple30.6361.9
4Apple246.3361.9
5Apple85361.9
6Orange112
7Orange412
8Orange712
9Banana88
Sum Unique
Cell Formulas
RangeFormula
C2:C9C2=SUM(UNIQUE(FILTER(B$2:B$9,A$2:A$9=A2)))
 
Upvote 0
Solution
The array formula used for all versions, in C2 then copied down
Excel Formula:
=SUM(($A$2:$A$9=A2)*$B$2:$B$9/MMULT(($A$2:$A$9=TRANSPOSE($A$2:$A$9))*($B$2:$B$9=TRANSPOSE($B$2:$B$9)),ROW($A$2:$A$9)^0))
 
Upvote 0
Thank you very much for all of your responses. I have also updated my account details.

I tested all of the responses and ended up settling on you sum unique filter approach Peter. Mostly due to the fact that it was easier for me to figure out how to add in a second filter criteria (which I had omitted for simplicity).

Final formula being:
=SUM(UNIQUE(FILTER(C$2:C$9,(A$2:A$9=A2)*(B$2:B$9=B2))))

1654118604895.png


Cheers,
Milos
 
Upvote 0
I have also updated my account details.
According to Microsoft's Help on the UNIQUE function (& FILTER) it is not available in Excel 2016, so have you updated correctly? Perhaps you actually have Microsoft 365 or Excel 2021?

1654156410776.png
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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