Sum TWO columns and delete rows

cdrobinson83

New Member
Joined
May 3, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to figure out how I can sum columns I and J while deleting the rows in the process that are deemed duplicates. Match criteria are columns A,C,E,F,H,K, and L. Example below of what I'm trying to do. Is anyone able to help? I can't for the life of me figure it out. I've looked at other posts and I just can't apply the logic.

Before:

1694892799079.png


After:

1694892927609.png
 

Attachments

  • 1694892612801.png
    1694892612801.png
    27.3 KB · Views: 7
  • 1694892645307.png
    1694892645307.png
    14.2 KB · Views: 7

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Rather than have us try to recreate your data to test, please upload your sample data using XL2BB.
 
Upvote 0
Sorry about that. I'm not able to download that extension. Does the below help?

AccountAccount NameFirmLopIdExchange codeFuture codeDescCTYMEx Long QtyAs Short QtyStrike PricePut/Call ValueEDSP of undl.ppmITM/ATM/OTMClassSubclassFirm LEIAccount LEIBusiness Close DateExpiration DateTrade TimeMIC CodeContract ISINBuy/Sell
111​
aaaMxxxxxx9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
15​
95.75​
P
95.23​
ITMCIB
222​
bbbMyyyyyy9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
50​
95.75​
P
95.23​
ITMCIB
333​
cccMzzzzzz9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
70​
95.75​
P
95.23​
ITMCIB
111​
aaaMxxxxxx9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
15​
95.75​
P
95.23​
ITMCIB
222​
bbbMyyyyyy9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
50​
95.75​
P
95.23​
ITMCIB
333​
cccMzzzzzz9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
70​
95.75​
P
95.23​
ITMCIB
111​
aaaMxxxxxx9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
15​
95.75​
P
95.23​
ITMCIB
222​
bbbMyyyyyy9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
50​
95.75​
P
95.23​
ITMCIB
333​
cccMzzzzzz9CS0PUT SEP 23 3M SOFR 1YMC 9575
202309​
0​
70​
95.75​
P
95.23​
ITMCIB
 
Upvote 0
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Duplicates" = Table.Distinct(Source, {"Account", "Firm", "Exchange code", "Future code", "CTYM", "Strike Price", "Put/Call Value"})
in
    #"Removed Duplicates"
 
Upvote 0
"Expression.Error: We couldn't find an Excel table named 'Table1'."

Is there something I need to name?
 
Upvote 0
Yes, the data you have shown as your source data needs to be named Table1 or change the code to reflect the table name you have used. The following may help

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
Thank you very much. I have it removing the dupes now but I need it to also sum columns "Ex Long Qty" and "As Short Qty" as well.
 
Upvote 0
Does that need to be summed by Account Name? In Total? In your example if by account name, then there is nothing to do unless your example is not representative of your actual data. Please expand your needs explanation.
 
Upvote 0
Sorry about that. I thought I mentioned that in my first post. I need to delete any "duplicates" based on criteria "Account", "Firm", "Exchange code", "Future code", "CTYM", "Strike Price", "Put/Call Value" while taking the quantities in "Ex Long Qty" and "As Short Qty" and summing them. Before and after below.

1695252331178.png


1695252346064.png
 
Upvote 0
Apologies if I missed that requirement. Because I had to copy and Paste from your data that was not posted with XL2BB, I had to change the data type as shown in the second line. When I copied and pasted it to excel it came over as text. You may not need that line of Mcode.

Try this:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ex Long Qty", type number}, {"As Short Qty", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Account", "Firm", "Exchange code", "Future code", "CTYM", "Put/Call Value"}, {{"Sum Ex Long Qty", each List.Sum([Ex Long Qty]), type text}, {"Sum As Short Qty", each List.Sum([As Short Qty]), type text}})
in
    #"Grouped Rows"
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,869
Members
449,130
Latest member
lolasmith

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