I have this table (vol_week) with four columns. Example:
date_ent | ped_kg | prd_kg | ref_kg
12/9/2017 | 345,22 | 321,23 | 12,56
I'm trying to calculate (ped_kg - prd_kg + ref_kg), but the query returns erratic values. Sometimes correct, sometimes close values.
SELECT date_ent, iif((Sum(ped_kg)-Sum(prd_kg)+Sum(ref_kg))<0,0,(Sum(ped_kg)-Sum(prd_kg)+Sum(ref_kg))) AS sld_kg
FROM vol_week
WHERE date_ent Is Not Null
GROUP BY date_ent
ORDER BY date_ent
I'm using MS Query in MSExcel.
EDIT: Problem solved :)
The query was calculating using negative values. This way the query consider zeros from <0,0
condition:
SELECT date_ent, Sum(iif(((ped_kg-prd_kg)+ref_kg)<0,0,(ped_kg-prd_kg)+ref_kg)) AS sld_kg
FROM vol_week
WHERE date_ent Is Not Null
GROUP BY date_ent
ORDER BY date_ent