473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Use of Nz statements for 3 different arguments

418 256MB
I tried to browse through several postings on Nz and iif statements. Coudln't find one that matches what I am looking for.

To calculate "Balance" there are 3 different situation

1. Balance = [Authorized] - [Expensed]

2. For balance where[Expense] = 0 I used
Balance: ([Authorized] - Nz([SumOfExpense],0))

3. For Expense is less than 0 (a negative due to overspending) is where I got stuck. When I tried iif statement it skipped where Expense has a zero value.

How do I capture all three situations in one function? Can I use a Nz statement to calculate Balance for all three situations? What I mean is to calculate Balance 1)iff Expense is Zero, do this, if Expense is less than Zero, do this, Otherwise Authorized less Expense equals Balance.

Can someone please help me with this?

Many thanks in advance.
Aug 6 '14 #1
5 1012
NeoPa
32,556 Expert Mod 16PB
Your question leaves a number of ambiguities about what you are dealing with.

From the name of [SomOfExpense] it seems clear that :
  1. The name of the field is [Expense] rather than [Expensed] as indicated in point #1.
  2. You are working across multiple records rather than within any particular record.
In that case I expect you'll need the code you have in point #2 for all circumstances - assuming you have :
Expand|Select|Wrap|Line Numbers
  1. SumOfExpense: [Authorized]-Sum([Expense])
Alternatively, the following should always work :
Expand|Select|Wrap|Line Numbers
  1. Balance: [Authorized]-Nz(Sum([Expense]),0)
Of course, you do understand that for this to work as you have it you must GROUP BY [Authorized].

Frankly, this would all be much clearer if we knew more precisely what we were working with. Sometimes suggesting an answer based on guesswork can be more misleading that helpful.
Aug 6 '14 #2
MNNovice
418 256MB
NeoPa,
Sorry for all the confusions caused by my inability to explain things better.

I have a query to calculate a balance amount which is basically the difference between authorized amount ([Authorized])and expensed amount ([Expense]). This query is based on two other queries: one has the [SumOfExpense] and other query has the [Authorized].

Balance = [Authorized] - [SumOfExpense]

I am having problem coming up with the correct balance where [SumOfExpense] is either zero or a negative number. When I use Nz statements I get the correct balance where [SumOfExpense] is zero. But I cannot find the right function to get to the correct Balance incorporating all 3 situations, i.e., [SumOfExpense] is either zero or a negative or a positive number. If it's a negative number, for example, if authorized amount was $100 and someone spent $300 then the balance should be (200) but i get $100 - (300) = 400.

Hope this explains my hopeless situation. If not, let me know. Thanks again.
Aug 6 '14 #3
NeoPa
32,556 Expert Mod 16PB
This still doesn't make sense Mareena.

On the one hand you say [SumOfExpense] reflects the total of all expenses. In this case it should be $300.

On the other you say the value for [SumOfExpense] is -$300 (or (300)).

If it is true that the value in [SumOfExpense] is actually (300) then the problem is not with this formula but with the values coming through to it. If the value desn't represent the actuality then the problem is right there - with the data coming in.

If, on the other hand, you are saying that you need to treat all values as positive regardless of whether they are positive or negative (And I'm guessing here because you haven't even hinted at that yet.) then we can handle that quite easily :
Expand|Select|Wrap|Line Numbers
  1. Balance: [Authorized]-Abs(Nz(Sum([Expense]),0))
Abs() returns the absolute value of any number passed. IE. It turns negative values into their positive equivalents.

If none of this helps then I'm going to need to question you to see if I can work out what it is we're actually dealing with.
Aug 6 '14 #4
MNNovice
418 256MB
What I meant is that when the authorized amount was $100 but the expense total was $300 then they have overspent by $200. So the total should be a negative $200. In this example the expense amount is a negative number (over the budget - they will get $100 that was authorized and will be in a hole for the balance i.e., negative $200. This would tell a manager that they will need to transfer funds from another expense account to make the authorized amount higher (in the event they have more expenses to come) or equal to $300.

What perhaps I didn't get to explain is that [SumOfExpense] = [Authorized] - [Expense]

-200 = 100 - 300

Hope this helps. Thanks.
Aug 6 '14 #5
NeoPa
32,556 Expert Mod 16PB
MNNovice:
What perhaps I didn't get to explain is that [SumOfExpense] = [Authorized] - [Expense]
If this means what I think it means then you can't sensibly use [SumOfExpense].

I need to talk with you later to see if we can make some sense of this together. I'm afraid what is here so far consists of very little that makes sense and much that seems contradictory. I'm struggling even to guess what we might be dealing with.

Please excuse me if I sound like I'm criticising you. I don't mean to. I'm just explaining why I can't help as things stand. On the other hand, I'm sure we can get to the bottom of things quite quickly and easily once we know what it is we're dealing with.
Aug 6 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: ios | last post by:
Hi Can someone tell me what is different between below case? strcpy(eventname, "MDCX_RSP"); and sprintf(eventname, "MDCX_RSP"); Thanks, Leon
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
15
by: Pohihihi | last post by:
This might sound little stupid to many but I was thinking that when we can use object why we really need event args to pass in any functions e.g. bool MyFunction(object sender, System.EventArgs...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
0
by: donal.conlon | last post by:
I'm using a few threads to run a commandline tool and read the outputs. What I want to do is run the tool several times with different arguments every time. i.e.run the process in its own thread,...
2
by: Bit byte | last post by:
I have a base (abstract) class with a public method foo delared as: virtual BaseClass* foo(..)=0; I wnat to derive two classes A and B from Baseclass so that I return a pointer for A and B...
13
by: dtshedd | last post by:
I am having trouble with arguments in a javascript routine. What I am trying to do is to limit the size of numbers to ten digits but make use of the significant places if the number is less than...
22
by: karthikbg | last post by:
Hi, I have a Board of Coldfire communicating with a PC on the other side. The PC will be sending via TCP/IP some 5000 different command identification numbers only ( consider 1 to 5000 ) at 1...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
1
by: Tom Harris | last post by:
Hi, Is there a way to pass arguments to TestCases when running tests? I have a test suite that need to be configured slightly differently for 3 different products, and rather than do a hack I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.