Skip to main content
Answer

Using a IIF function

  • August 23, 2024
  • 5 replies
  • 481 views

Forum|alt.badge.img+1

I have an Generic Inquriy column called orig_ord_type which, depending on the ARInvoice.DocType could either be a ‘C’ for Credit or an ‘O’ for Invoices and Debit Memos. My logic for this  is =IIF(LEFT([ARInvoice.DocType], 6)  =  'Credit', 'C', 'O') which accounts for Credit Memos and Credit WO (Write Offs) which should be coming up as ‘C’, but everything is coming up as an ‘O’. I’ve even tried using =IIF([ARInvoice.OrigDocAmt] < 0.00, ‘C’, ‘O’) and anything listed as a Credit still had an O in the column. If anyone has other ideas, they would certainly be appreciated, even using the =SWITCH function. I’ve tried the =SWITCH and I received an error about the MEMO token.

 

Best answer by DrewNisley

I would also note that when using fields in an expression, it will use the value of how it is stored in the database, not how it appears to the user.

I like the Switch statement better for something where there more values involved, it seems a little simpler.

Use something like this:

Switch([ARInvoice.DocType]= 'INV', 'O', [ARInvoice.DocType]= 'DRM', 'O', [ARInvoice.DocType]= 'CRM', 'C', [ARInvoice.DocType]= 'SMC', 'C')

5 replies

Laura03
Captain II
Forum|alt.badge.img+19
  • Captain II
  • August 23, 2024

Hello,

Document amounts aren’t stored as negatives in the database; that’s why everything turned into “O”.

I use nested IIf statements to solve a situation like yours.  (I’m not a programmer.)  Try something like this:

IIF(LEFT([ARInvoice.DocType], 6)  =  'Credit', 'C',

IIF(LEFT([ARInvoice.DocType], 5)  =  'Debit',  ‘D’,

IIF(LEFT([ARInvoice.DocType], 5)  =  ‘Prepa’, ‘P’,    [etc.]

'O' ) ) )

 

Laura


DrewNisley
Pro I
Forum|alt.badge.img+3
  • Pro I
  • Answer
  • August 23, 2024

I would also note that when using fields in an expression, it will use the value of how it is stored in the database, not how it appears to the user.

I like the Switch statement better for something where there more values involved, it seems a little simpler.

Use something like this:

Switch([ARInvoice.DocType]= 'INV', 'O', [ARInvoice.DocType]= 'DRM', 'O', [ARInvoice.DocType]= 'CRM', 'C', [ARInvoice.DocType]= 'SMC', 'C')


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • August 23, 2024

I did initially try the =SWITCH but the logic was not correct. Your solution worked perfectly. I thank both Laura02 and you for responding with excellent suggestions. 


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • August 26, 2024
  • DrewNisley I would mark your answer as the Best Answer but there is no where to mark it as such. Thank you.


DrewNisley
Pro I
Forum|alt.badge.img+3
  • Pro I
  • August 26, 2024

@wmatthews1877 It is marked already, no worries 😊