You can use an IF function to check whether the adjacent cell contains “YES” or “NO” and then subtract or add the value accordingly.
For example, if your summary column is column A and the column with “YES” or “NO” is column B, you could use a formula like this in the cell below the summary of all the numbers:
=IF(B2="YES", A2-SUM(A:A), A2+SUM(A:A))
This formula checks if the value in cell B2 is “YES”. If it is, it subtracts the value in cell A2 from the sum of all the numbers in column A.
If the value in cell B2 is not “YES”, it adds the value in cell A2 to the sum of all the numbers in column A.