negative values to be returned as zero

G

Guest

i want to make a query in order to calculate volumes
in some causes when i make summation i have both negative and positive values
i want to get the negative values as equal to zero in the query
 
V

Van T. Dinh

Try using IIf in your expression like:

NonNegVal: IIf([YourVal] < 0, 0, [YourVal])

and then you can sum the NonNegVal
 
M

Michel Walsh

You want to consider a negative value to be zero BEFORE making the
summation, of AFTER?

before:

SELECT id, SUM(volume)
FROM somewhere
WHERE volume>0
GROUP BY id



after:

SELECT id, iif(SUM(volume)<0, 0, SUM(volume))
FROM somewhere
GROUP BY id




Hoping it may help,
Vanderghast, Access MVP
 
J

John Spencer

Use a calculated field

IIF(Sum([TheField])<0,0,Sum([TheField]))

In the grid:
Field: NegToZero: IIF(Sum([TheField])<0,0,Sum([TheField]))
Total: Expression


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Guest

thank you for your help

John Spencer said:
Use a calculated field

IIF(Sum([TheField])<0,0,Sum([TheField]))

In the grid:
Field: NegToZero: IIF(Sum([TheField])<0,0,Sum([TheField]))
Total: Expression


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

fytos said:
i want to make a query in order to calculate volumes
in some causes when i make summation i have both negative and positive
values
i want to get the negative values as equal to zero in the query
 
G

Guest

thank you for your help


Michel Walsh said:
You want to consider a negative value to be zero BEFORE making the
summation, of AFTER?

before:

SELECT id, SUM(volume)
FROM somewhere
WHERE volume>0
GROUP BY id



after:

SELECT id, iif(SUM(volume)<0, 0, SUM(volume))
FROM somewhere
GROUP BY id




Hoping it may help,
Vanderghast, Access MVP
 
G

Guest

thank you for your help

Van T. Dinh said:
Try using IIf in your expression like:

NonNegVal: IIf([YourVal] < 0, 0, [YourVal])

and then you can sum the NonNegVal

--
HTH
Van T. Dinh
MVP (Access)




fytos said:
i want to make a query in order to calculate volumes
in some causes when i make summation i have both negative and positive
values
i want to get the negative values as equal to zero in the query
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top