Adding fields sum (1 Viewer)

Gismo

Registered User.
Local time
Today, 23:59
Joined
Jun 12, 2017
Messages
1,298
Hi all,

Quick question
Below is a table with temporary data
I need to add fields together
Query comes out blank
What am I doing incorrectly?

Profit/Loss: Sum([Financial Summary Tbl]![Total Sales (UGX)]-([Financial Summary Tbl]![Total Purchase (UGX)]+[Financial Summary Tbl]![Salaries]+[Financial Summary Tbl]![Accets]+[Financial Summary Tbl]![Promotions])-[Financial Summary Tbl]![Stock Adjustment])

1669133087650.png


1669133423825.png
 

Guus2005

AWF VIP
Local time
Today, 22:59
Joined
Jun 26, 2007
Messages
2,641
[Total Sales (UGX)] = NULL so the end result is NULL
same goes for ![Total Purchase (UGX)].
Use Nz to circumvent this problem

Code:
Profit/Loss: Sum(Nz([Financial Summary Tbl]![Total Sales (UGX)])
                -(Nz([Financial Summary Tbl]![Total Purchase (UGX)])
                 +Nz([Financial Summary Tbl]![Salaries])
                 +Nz([Financial Summary Tbl]![Accets])
                 +Nz([Financial Summary Tbl]![Promotions]))
                 -Nz([Financial Summary Tbl]![Stock Adjustment]))
 

Gismo

Registered User.
Local time
Today, 23:59
Joined
Jun 12, 2017
Messages
1,298
[Total Sales (UGX)] = NULL so the end result is NULL
same goes for ![Total Purchase (UGX)].
Use Nz to circumvent this problem
I sum them all together, for November, there is figures for all

Just Profit/Loss is blank

But NZ seems to work just fine
Thank you

1669133821064.png
 

Guus2005

AWF VIP
Local time
Today, 22:59
Joined
Jun 26, 2007
Messages
2,641
did you try using Nz?

If so, split the problem into smaller pieces.
Add a column profit/loss per record and see if there is any result before summing it all together.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Feb 19, 2002
Messages
43,300
Just to clarify, aggregate functions and domain function in forms, reports, queries ignore nulls but plain old arithmetic fails unless YOU handle potential null values.

So, Sum(a) will produce a correct result even if a contains null values but Sum(a + b) will not produce correct results if either a or b has even one null value). The second expression needs to be Sum(Nz(a,0) + Nz(b,0))
 

Users who are viewing this thread

Top Bottom