SumIf question - total items in a column if it meets a criteria

Hi and thanks in advance,


How do I make a formula (I'm guessing sumif may work??) that will total items if a condition in another column is met? For example, I'd like to total the number of Long and Short strategies but ONLY if they're Open like the yellow boxes in the screeshot. If they're closed, I don't want to total them.

Posted on Sep 26, 2023 8:24 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 30, 2023 9:57 AM

The formula provided by badunit works.

=COUNTIFS(B2:B7,"open",A2:A7,"long")


Now as a learning experience maybe you want to know why yours doesn't.

1- the calculation includes the result cell B9 itself, as it is within the blue rectangle. It cannot be, you only want to include cells B2:B7.

2- the use of AND is unnecessary because you only have one argument inside it, and harmful because it returns a single true/false value that's incompatible with COUNTIFS. COUNTIFS itself does an AND between all pairs of arguments, so the logic is: count the number of rows where on the same row "Open" is the value in the first range (B2:B7) AND "Long" is the value in the second range (A2:A7).


To make the formula easier to use for both the Long total and the Short total I'd modify it this way so it can be used for both totals without manual modification. Enter first in B9 and then copy and paste in B10 (or copy-drag with the yellow bubble at the base of the cell).

=COUNTIFS(B$2:B$7,"open",A$2:A$7,$A9)

5 replies
Question marked as Top-ranking reply

Sep 30, 2023 9:57 AM in response to lvcfp

The formula provided by badunit works.

=COUNTIFS(B2:B7,"open",A2:A7,"long")


Now as a learning experience maybe you want to know why yours doesn't.

1- the calculation includes the result cell B9 itself, as it is within the blue rectangle. It cannot be, you only want to include cells B2:B7.

2- the use of AND is unnecessary because you only have one argument inside it, and harmful because it returns a single true/false value that's incompatible with COUNTIFS. COUNTIFS itself does an AND between all pairs of arguments, so the logic is: count the number of rows where on the same row "Open" is the value in the first range (B2:B7) AND "Long" is the value in the second range (A2:A7).


To make the formula easier to use for both the Long total and the Short total I'd modify it this way so it can be used for both totals without manual modification. Enter first in B9 and then copy and paste in B10 (or copy-drag with the yellow bubble at the base of the cell).

=COUNTIFS(B$2:B$7,"open",A$2:A$7,$A9)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

SumIf question - total items in a column if it meets a criteria

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