I have this data:
name qty date flag
---------------------------------------------
abc 255 11/10/1986 12:00:00 AM IN
abc 300 11/10/2010 12:00:00 AM IN
abc 12 11/10/2012 12:00:00 AM OUT
abc 13 11/9/2010 12:00:00 AM OUT
NULL NULL NULL NULL
I want to get sum of qty
at that specific row:
flag
is "in", then it will add to the sumflag
is "out", then it will subtract from the sumThe most common reason for AutoSum not working in Excel is numbers formatted as text. At first sight, those values may look like normal numbers, but Excel regards them as text strings and does not include in calculations.
Check for Automatic Recalculation On the Formulas ribbon, look to the far right and click Calculation Options. On the dropdown list, verify that Automatic is selected. When this option is set to automatic, Excel recalculates the spreadsheet's formulas whenever you change a cell value.
The syntax of the array formula will be =SUM(IFERROR(A1:A8,0)). In this case, the IFERROR function is evaluating the contents of cells A1:A8 and, if there is an error, replacing the error value with zero. The SUM function is then used to sum the values. Enter this function is cell A11.
SELECT SUM(case flag when 'IN' then qty else -qty end)
from table
WHERE ..... Your conditions here ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With