Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Concetanate and IIf Function

Hi there,

Wondering if it was possible to achieve a multiple iif function with a concatenation string. I have written the following code in order to try and obtain multiple values based on an iff statement. Basically what I am trying to achieve is for example this:

If companyname has more than one expiry dates on an agreement then my expression will write the agreement names that qualify i.e. "AgrA, AgrB" etc.
ContractType: IIf([AgrAExpiryDate]>0,"AgrA",+IIf([AgrBExpiryDate]>0,"AgrB",+IIf([AgrCExpiryDate]>0,"AgrC",+IIf([AgrDExpiryDate]>0,"AgrD",+IIf([AgrEExpiryDate]>0,"AgrE",+IIf([AgrFExpiryDate]>0,"AgrF",+"Other"

Open in new window

0
databarracks
Asked:
databarracks
  • 4
  • 3
1 Solution
 
databarracksAuthor Commented:
If this makes the explanation easier, where in the relative expiry date fields in the multiple agreement types are <=Date()+90 please return the text "AgrA" OR "AgrB" OR "AgrC" but there is a high possibility that there would be two contract types expiring in the same period and therefore need to have the ability to return the two agreement types that qualify.

This as vaguely explained in my original post.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can "nest" multiple IIF statements basically by using the "False" section of the IIF to include another IIF:

IIF(MyValue=1, "Yes", IIF(MyValue=2, "No",IIF(MyValue=3,"Maybe")))

However this get exceptionally convoluted very quickly and can be a bear to manage down the road. You might be able to use the Switch function in your query:

contracttype: SWITCH(AgrEpricyDate>0, "AgrA", AgrExpiryDate>30, "AgrB")

Or you could build a function that did this, and then use that function in your query.

Note all of these can result in poor performance.
0
 
databarracksAuthor Commented:
I understand nesting multiple iif functions but that doesn't enable me to return the options I require. Hmmmm, I think I may have landed myself in a pickle here. The key bit is concatenating as I have already made it return one value as indicated originally, but if I have two types of agreements expiring at the same time it would only return the first one and not both.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
databarracksAuthor Commented:
Could someone please help?
0
 
GRayLCommented:
Try this.  I am assuming that if all of the first six tests are 0 then you want the word "Other".

Switch([AgrAExpiryDate]>0,"AgrA ") & Switch([AgrBExpiryDate]>0,"AgrB ") & Switch([AgrCExpiryDate]>0,"AgrC ") & Switch([AgrDExpiryDate]>0,"AgrD ") & Switch([AgrEExpiryDate]>0,"AgrE ") & Switch([AgrFExpiryDate]>0,"AgrF ") & IIf(IsNull(
Switch([AgrAExpiryDate]>0,"AgrA" ) & Switch([AgrBExpiryDate]>0,"AgrB ") & Switch([AgrCExpiryDate]>0,"AgrC ") & Switch([AgrDExpiryDate]>0,"AgrD ") & Switch([AgrEExpiryDate]>0,"AgrE ") & Switch([AgrFExpiryDate]>0,"AgrF")), "Other", "")
0
 
GRayLCommented:
I did some testing and this was the only way I could concatenate one to six results where the applicable  dates tested positive. Just remember this will fail if any of the dates are prior to 31 Dec 1899.
0
 
databarracksAuthor Commented:
Spot on with the recommendation and was very concise with the solution
0
 
GRayLCommented:
Thanks, glad to help
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now