Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Apple Numbers, my first use of Sumif...duh

To understand my problem with Apple numbers it would be clearer if you just recreated it. This is for simple stock trading, - (buy low, sell high) = long, (buy high, sell low) = short, both can be profitable, so ($100) in a short is a win. 


COLUMNS;

  1. (Col B) Qty# 
  2. (Col D) SHORT (checkbox) if checked = Short, if not = Long
  3. (Col E) Entry $price
  4. (Col F) Exit $price
  5. (Col K) Long$ (Q3−P3) calculates the win or loss
  6. (Col L) Short$ (P3−Q3) calculates the win or loss
  7. (Col P) Invested $Total (E3×ROUND($B3,4))
  8. (Col Q) Gain/Loss $ (F3×B3)
  9. (Col K16) Sums column L for the Long trades (SUMIF(D3:D14,"=false",K3:K14)
  10. (Col L16) Sums column M for the Short trades (SUMIF(D3:D14,"=True",L3:L14)
  11. (Col M16) adds Long & Short Total (SUM(K16,L16)


WORKFLOW, (Enter these values to easily see problem)

  1. Stock Ticker (Not Needed)
  2. Enter Qty (10 for each of the 4 trades)
  3. Check if SHORT or Unchecked if LONG (Short, Long, Short, Long)
  4. Enter Entry Price ($100. For each of the 4 trades)
  5. Enter Exit Price ($90, $110, $90, $110)


CALCULATIONS ARE…

Col K (Long) (Q3−P3) 

Col L (Short) (P3−Q3)

Col P ($ Invested Total) (E3×ROUND($B3,4)

Col Q ($ Profit/Loss) (F3×B3)


VALUES I HAVE…

Total for Long K16 should be $200

Total for Short L16 should be $200

Grand Total M16 should be $400.


PROBLEM:

If you have everything the way I have it you should see ($400 Total).

 

Now All trades are Wins (2 long wins and 2 short wins)


If I accidentally DIDN’T check Col D6 to make it a Short

and then I DID check it turning it into a short, now it shows a

Loss. Notice what happens in the $400 Total.


A correction of a $100 profit (as a Long) now turns into a

$100 Loss (as a Long) on the 4th trade.


This is where I get lost.

$100 profit is actually a $100 loss which is a $200 difference.

BUT the trade ONLY has a $100 Value. 


So which is it, and how do I correct it? 


Sorry for the long post, 

Thank you 


I don’t think I can send the spreadsheet it says I need to update OS and Numbers.

Running Ventura 13.6.8 Numbers 14.1 (7040.0.73).


Areas that are greyed out have no relevance to the problem.

iMac 27″

Posted on Nov 30, 2024 2:03 PM

Reply
16 replies

Dec 2, 2024 6:11 AM in response to Yellowbox

Ian, this is definitely on the right track...BUT

Unfortunately we are going against the basic math involved.

See screenshot.

Row 2 = a SHORT gain

Row 3 = a LONG gain

Row 4 = a SHORT loss

Row 5 = a LONG loss

  • = Correct Outcome

NG = INcorrect Outcome


NG = So in Row 2 we have a normal math outcome of a loss Entry $100 Exit $90 = a loss

but in the SHORT world that is a gain so the red ($100) should be a black $100


  • = In Row 3 we have a normal math outcome of a win Entry $100 Exit $110 = a gain.

and we have a proper outcome because it follows normal math and shows a black $100


NG = In Row 4 we have a normal math outcome of a win Entry $100 Exit $110 = a gain.

but in the SHORT world that is a LOSS so the Black $100 should be a Red ($100)


  • = In Row 5 we have a normal math outcome of a loss Entry $100 Exit $90 = a loss

and in the LONG world that is a LOSS so the Red ($100) is correct.


The easy way to see the problem is to check and UNcheck the Short checkbox.


So we're 50% there! I hope you are still enjoying this challenge Ian?


Thanks

Billy

Nov 30, 2024 3:34 PM in response to Bill K

Hi Bill,



Syntax for SUMIF: SUMIF(test-values, condition, sum-values)

Formula in K15 is SUMIF($D,FALSE,K)

Formula in K15 is SUMIF($D,TRUE,K)


Bill K wrote:

If I accidentally DIDN’T check Col D6 to make it a Short
and then I DID check it turning it into a short, now it shows a
Loss. Notice what happens in the $400 Total.

I'm not sure what you mean. D6 did not feature in your example. What brings it in now?


Regards,

Ian.

Nov 30, 2024 9:02 PM in response to Bill K

Hi Billy,

Bill K wrote:

Sorry for my typo, I mean D5.

No worries. We all make typos 🫢.

For example, I wrote:

Formula in K15 is SUMIF($D,TRUE,K)

What I meant was,

Formula in L15 is SUMIF($D,TRUE,L)


Bill K wrote:

VALUES I HAVE…

Total for Long K16 should be $200

Total for Short L16 should be $200

Grand Total M16 should be $400.


From your description, sums are in row 16.

From your screen shot, the sums are in row 15.

Let's assume you meant row 15 😎. Cool.


Now ticking D5:



Yes, I see what you mean, but I do not understand the formulas in P and Q, hence the formulas in K and L. Sorry.


Regards,

Ian.

Dec 1, 2024 11:39 PM in response to Bill K

Bill K wrote:

This makes me think about what I said before…
“At one point I thought what if when the value is a $100 win in the Long column and then instead
of a ($100) deduction being put in the Short column it puts a $0 then it would only be a $100 change".

Hi Billy,

Good idea. Try this (I added data for row 6)


Formula in K2 is IF(D2,0,Q2−P2)

Formula in L2 is IF(D2,Q2−P2,0)


Regards,

Ian.

Dec 3, 2024 6:29 AM in response to Yellowbox

Ian,

I thought I would be sending you the final, however the new drop down menu to select if it's a Short or Long does the calculation however is very slow 3 clicks to do what the checkbox does in one. I used the SWITCH(S5,"Long",F5−E5,"Short",E5−F5) formula for Col K and tried to change the "Long" to "False" and the "Short" to "True" but it didn't work. Any thoughts. I added some notes on the latest screenshot.


For the screenshot I separated columns (Long Gains, Short Gains, % Long and % Short) I am questioning their purpose. I would like to know the percentage but that's two columns and same for Long and Short gains. Analysis of trades is important but 4 columns trying to understand how to have only 2 to give info.


By the way I posted some info by replying to me, where here, I am replying to you. Do you get a notice for both?


*For some reason this website is not allowing me to upload the screenshot, will add later hopefully it will work then.


Dec 4, 2024 11:25 AM in response to Yellowbox

Hi Ian, 

Here is a minimized table I have been going nuts so I needed to clear the clutter.


CALCULATIONS ARE…

Col E LONG Gains IF(B2,0,I2−H2)

Col F SHORT Gains IF(B2,I2−H2,0)

Col G P/L Per Trade IF(B2,0,D2−C2)

Col H Invested. C2×$A2

Col I Profit/Loss. D2×A2


SEE VALUES SET ON SCREEN SHOT


Rows 2 & 3 are profitable trades

Rows 3&4 are losses


If you change B2 to a short by checking the checkbox in Col B

The value shifts to the SHORT col F (correct), BUT that would be a LOSS for a SHORT

So that should be a Red ($500).


Cell F3 should be $300 in black.

Cell F5 it should be ($100) in red.


So even though the checkbox works correctly in shifting the number to

The Short column, it doesn’t make it a Loss.


So I guess you can say as soon as you check that box and it turns RED

That is what should happen to the number, If it is a loss (Buy High/Sell Low).


I hope that is clear Mate, just saw that you’re an Aussie.


Billy

Nov 30, 2024 4:27 PM in response to Yellowbox

Hi Ian,

Sorry for my typo, I mean D5.

So then you'll see the $200 reduction, instead of what I think should be only $100?

The checkbox column D toggles between adding/subtracting from the appropriate column

either the Long or Short column.


At one point I thought what if when the value is a $100 win in the Long column and then instead

of a ($100) deduction being put in the Short column it puts a $0 then it would only be a $100 change.


Of course if it is a True loss then it would be correct to have ($100) to calculate properly

Thanks for the super quick reply Ian.

Billy

Dec 1, 2024 8:09 AM in response to Yellowbox

Hi Ian,

For simplicity I changed Col P formula to (E2×$B2), Col Q stays at (F2×B2). Same results just simpler.

*Previously needed to round off Qty for trade blocks of $10k, but now is handled outside of this spreadsheet.

*My screwup was I started to write out all the info and then I said I should get rid of unnecessary columns

which changed the formulas. SORRY!


So Col P calculates Col E Entry Price x QTY (E2×$B2)

Col Q calculates Col F Exit Price x QTY (F2×B2)


Col K calculates the difference between Col P and Col Q for Longs (Q2−P2)

Col L calculates the difference between Col P and Col Q for Shorts (P2−Q2)

  *Notice the calculations are reversed to force a positive (black) value if a win in short.


This makes me think about what I said before…

“At one point I thought what if when the value is a $100 win in the Long column and then instead

of a ($100) deduction being put in the Short column it puts a $0 then it would only be a $100 change".


Billy



Dec 4, 2024 6:20 AM in response to Bill K

Ian, Multitasking has gotten the better of me, my apologies!

I am currently going back to your simple GREAT formula, (which also allows me to get back to the checkbox) because this new one I found has the same original problem, I think I was blinded by my eagerness to get this over with. I will post ASAP.

Thank you again. Billy

Dec 4, 2024 7:18 AM in response to Bill K

Hi Billy,

You wrote:

"By the way I posted some info by replying to me, where here, I am replying to you. Do you get a notice for both?"


Yes. My first reply automatically subscribed me to this discussion. I get an email notification of each reply, no matter who replies to whom.


A note about screen shots. Please include the column letters and the row numbers. That makes it easier to follow the formulas. For example, your SWITCH formula refers to S5. I did not know that your table went as far as column S!


Anyway, I await your latest update.

Regards,

Ian.

Apple Numbers, my first use of Sumif...duh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.