Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing an IIF statement with multiple iff's

Status
Not open for further replies.

Stayingahead

IS-IT--Management
Dec 20, 2004
8
US
I am pulling financial info from a "table view" from our central office. Problem is all transaction amounts show up as a positive figure. I need to write an IIF statement to show Voided Deposits and withdrawls as negative figures. Below is all the codes I have to include or work with.

TransactionTypeCode TransactionTypeTxt
D Deposit
DC Deposit-Consumer
W Withdrawl
VDC Void Deposit Consumer
TW Transfer Withdrawl
VW Void Withdrawl
VDP Void Deposit Program
VD Void Deposit
TD Transfer Deposit
DP Deposit Program

Below is the IIF statement I wrote, but is not returning any amounts. What do I need to do different to get my amounts to show up correctly?

Transactions: IIf([transactiontypecode]="w",IIf([transactiontypecode]="TW",IIf([transactiontypecode]="vdc",IIf([transactiontypecode]="vdp",IIf([transactiontypecode]="vd",[transactionamt]*-1,[transactionamt]*1)))))

Also, can you write an IIF statement using the "*" wildcard character?
 
there's 2 results right, * by -1 or +1...

so why not use patern matching or something to categorise them?

e.g.

iif(TransactionTypeCode = "A" or TransactionTypeCode = "B", *-1, *1)

p.s. F1 for pattern matching within jet sql...

--------------------
Procrastinate Now!
 
That's not how you use an IIf function.

Try:

Code:
Amount  = IIf([transactiontypecode]="w" or [transactiontypecode]="TW" or [transactiontypecode]="vdc" or [transactiontypecode]="vdp" or [transactiontypecode]="vd", [transactionamt] * -1, [transactionamt])

However, I'd use a Select Case statement:

Code:
Select Case [transactiontypecode]
Case "W", "TW", "VDC", "VDP", "VD"
    Amount = [transactionamt] * -1
Case Else    
    Amount = [transactionamt]
End Select
 
Why the extra calculation
use
Code:
Amount  = IIf([transactiontypecode]="w" or [transactiontypecode]="TW" or [transactiontypecode]="vdc" or [transactiontypecode]="vdp" or [transactiontypecode]="vd", -[transactionamt] , [transactionamt])

for the case Statment
Code:
Select Case [transactiontypecode]
Case "W", "TW", "VDC", "VDP", "VD"
    Amount = -[transactionamt] 
Case Else    
    Amount = [transactionamt]
End Select
 
Thanks. That worked. I was trying to make something simple, difficult.
 
A simpler way:
Transactions: IIf([TransactionTypeCode] In ("W","TW","VDC","VDP","VD"),-[transactionamt],[transactionamt])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You can't use IN with an IIf statement, can you? It's only for SQL statements.
 
I thought that the OP was a query grid expression ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top