Sum column based on unique values in another column

samide2001

New Member
Joined
Feb 2, 2024
Messages
11
Office Version
  1. 365
Platform
  1. MacOS
All of the formulas I am doing will be on a summary tab that looks at data added on another tab "Jan". So I cannot add helper columns. The number of rows per column will change each month, and the number of duplicates will also change. So, if the formula could be derived to look at the entire column that would be great!

On the summary tab, I need the formula to look at the data in column W and sum the values for the unique numbers in column A. I also need the formula to subtract out the values from column W if column B has "canceled" as the status (also removing any duplicates). So, for the example below the correct value returned should be $7.65 for column W based on the uniqe values of column A - canceled orders in Column B.

2024 - TikTokShop Sales and Fees - Quick Numbers.xlsx
ABCW
1Order IDOrder StatusOrder SubstatusTaxes
2Platform unique order ID.Current order status.
3576577737861468321ShippedIn Transit1.09
4576575207724716077ShippedIn Transit5.26
5576575207724716077ShippedIn Transit5.26
6576575207724716077ShippedIn Transit5.26
7576575207724716077ShippedIn Transit5.26
8576573793136054581ShippedDelivered0.7
9576568733552841200ShippedDelivered0.6
10576568733126005232CanceledCanceled0.6
Jan


Here is the summary tab: The formula I need will go in cell B6

2024 - TikTokShop Sales and Fees - Quick Numbers.xlsx
ABC
3Revenue
4Sales$ 93.00$ -
5Shipping$ 9.31$ -
6Sales Tax$ 7.65$ -
7Canceled Orders$ 10.00$ -
8Shop Revenue$ 84.66$ -
9
10Expenses
11Selling Expenses
12Referral Fees$ 4.19$ -
13Affiliate Commisions$ 3.00$ -
14Shipping Fee$ 16.98$ -
15Total Expenses$ 24.17$ -
16
17Net Profit$ 60.49$ -
Monthly Summary
Cell Formulas
RangeFormula
B4B4=SUM(Jan!$M:$M)
B5B5=SUMIF(Jan!$B:$B, "<>"&"Canceled", Jan!$Q:$Q)
C4C4=SUM(Feb!$M:$M)
C5C5=SUMIF(Feb!$B:$B, "<>"&"Canceled", Feb!$Q:$Q)
C6C6=SUM(Feb!$W:$W)
B7B7=SUMIF(Jan!$B:$B, "Canceled", Jan!$Y:$Y)-SUMIF(Jan!$B:$B, "Canceled", Jan!$W:$W)
C7C7=SUMIF(Feb!$B:$B, "Canceled", Feb!$Y:$Y)-SUMIF(Feb!$B:$B, "Canceled", Feb!$W:$W)
B8B8=SUM(B4+B5-B6-B7)
C8C8=SUM(C4+C5-C6-C5)
B12B12=-SUM('Jan2'!$Y:$Y)
C12C12=-SUM('Feb2'!$Y:$Y)
B13B13=-SUM('Jan2'!$AD:$AD)
C13C13=-SUM('Feb2'!$AD:$AD)
B14B14=-SUM('Jan2'!$Z:$Z)
C14C14=-SUM('Feb2'!$Z:$Z)
B15:C15B15=SUM(B12:B14)
B17:C17B17=B8-B15



I have tried a sumif formula with unique as the criteria, but got a spill error. When I moved it out this is the data I got (this was the first part before trying to figure out how to subtract column B):
2024 - TikTokShop Sales and Fees - Quick Numbers.xlsx
D
271.09
28$ 21.04
29$ 0.70
30$ 0.60
31$ 0.60
32$ -
Monthly Summary
Cell Formulas
RangeFormula
D27:D32D27=SUMIF(Jan!A:A,UNIQUE(Jan!$A3:A99999,FALSE,FALSE),Jan!W:W)
Dynamic array formulas.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
See if this does what you want.. however, I should note, I did not subtract any 'Canceled' values, I just did not include them in the sum. Looking at your summary sheet, it looks like you are taking care of actually subtracting them there.

Excel Formula:
=LET(u,UNIQUE(Jan!$A$3:$W$10,FALSE,FALSE),SUM(TAKE(FILTER(u,CHOOSECOLS(u,2)<>"Canceled"),,-1)))
 
Upvote 0
Or a trusty SUMPRODUCT ...

Excel Formula:
=SUMPRODUCT((1/COUNTIF(Jan!A3:A10,A3:A10))*(Jan!B3:B10<>"Canceled")*(Jan!W3:W10))
 
Upvote 0
See if this does what you want.. however, I should note, I did not subtract any 'Canceled' values, I just did not include them in the sum. Looking at your summary sheet, it looks like you are taking care of actually subtracting them there.

Excel Formula:
=LET(u,UNIQUE(Jan!$A$3:$W$10,FALSE,FALSE),SUM(TAKE(FILTER(u,CHOOSECOLS(u,2)<>"Canceled"),,-1)))
The result of this is formula is $23.43. For some reason the formula doesn't remove the duplicates from column A, which has to happen before I can subtract any canceled orders.
 
Upvote 0
How about
Excel Formula:
=LET(u,UNIQUE(Jan!A3:A10),SUM(SUMIFS(Jan!W:W,Jan!A:A,u,Jan!C:C,"<>canceled")/COUNTIFS(Jan!A:A,u)))
 
Upvote 0
The result of this is formula is $23.43. For some reason the formula doesn't remove the duplicates from column A, which has to happen before I can subtract any canceled orders.

This resulted divide by zero error.

Are you using these on larger data sets than what you provided as a sample? Perhaps there is something else in the data now that was not represented which may be throwing off the calculations?

Or see if Fluff's suggestion solves the issue.
 
Upvote 0
How about
Excel Formula:
=LET(u,UNIQUE(Jan!A3:A10),SUM(SUMIFS(Jan!W:W,Jan!A:A,u,Jan!C:C,"<>canceled")/COUNTIFS(Jan!A:A,u)))
This works for the data that was provided. How can I change the first unique range to look at more than A3:a10 in future formulas? I won't be the end user of the spreadsheet, so I need something that will be user-friendly for the end-user.
 
Upvote 0
How about
Excel Formula:
=LET(u,UNIQUE(filter(Jan!A3:A1000,Jan!A3:A1000<>"")),SUM(SUMIFS(Jan!W:W,Jan!A:A,u,Jan!C:C,"<>canceled")/COUNTIFS(Jan!A:A,u)))
 
Upvote 1
Solution

Forum statistics

Threads
1,224,900
Messages
6,181,636
Members
453,059
Latest member
jkevin

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