Applying additional logic (sign flip) within SUMIFS statement

karlosDavid

New Member
Joined
Aug 18, 2022
Messages
3
Office Version
  1. 365
Can anyone advise on how to streamline the aggregation logic below - I'd like to remove the column: "normalized_x" entirely and move the logic to within the aggregation statement.

Thanks for any help


Book1
BCDEFGHIJKLM
2
3commoditytypexnormalized_x
4GASBUY-1515
5GASSELL11
6GASBUY7-7
7POWERBUY14-14
8POWERSELL55
9POWERSELL-6-6
10
11Aggregation
12GASgains16(sum of positive values in normalized_x for GAS)
13losses-7(sum of negative values in normalized_x for GAS)
14POWERgains5
15losses-20
16
Sheet1
Cell Formulas
RangeFormula
F4:F9F4=IF(D4="BUY",E4*-1,E4)
F12F12=SUMIFS(F4:F9,F4:F9,">0",C4:C9,D12)
F13F13=SUMIFS(F4:F9,F4:F9,"<0",C4:C9,D12)
F14F14=SUMIFS(F4:F9,F4:F9,">0",C4:C9,D14)
F15F15=SUMIFS(F4:F9,F4:F9,"<0",C4:C9,D14)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi & welcome to MrExcel.
For F12 how about
Excel Formula:
=LET(a,E4:E9*IF(D4:D9="buy",-1,1),SUM(IF((a>0)*(C4:C9=D12),a)))
 
Upvote 0
Solution
Or:
Gains: =SUM(SUMIFS($E$4:$E$9,$D$4:$D$9,{"BUY","SELL"},$E$4:$E$9,{"<",">"}&0,$C$4:$C$9,D12)*{-1,1})
Losses: =SUM(SUMIFS($E$4:$E$9,$D$4:$D$9,{"BUY","SELL"},$E$4:$E$9,{">","<"}&0,$C$4:$C$9,D12)*{-1,1})
 
Upvote 0
Or:
Gains: =SUM(SUMIFS($E$4:$E$9,$D$4:$D$9,{"BUY","SELL"},$E$4:$E$9,{"<",">"}&0,$C$4:$C$9,D12)*{-1,1})
Losses: =SUM(SUMIFS($E$4:$E$9,$D$4:$D$9,{"BUY","SELL"},$E$4:$E$9,{">","<"}&0,$C$4:$C$9,D12)*{-1,1})
Thanks also
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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