Improve company productivity with a Business Account.Sign Up


Concetanate and IIf Function

Posted on 2011-02-14
Medium Priority
Last Modified: 2012-08-14
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

Question by:databarracks
  • 4
  • 3

Author Comment

ID: 34887066
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.
LVL 86
ID: 34887155
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.

Author Comment

ID: 34887196
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.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.


Author Comment

ID: 34887610
Could someone please help?
LVL 44

Accepted Solution

GRayL earned 500 total points
ID: 34890184
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", "")
LVL 44

Expert Comment

ID: 34890239
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.

Author Closing Comment

ID: 34897082
Spot on with the recommendation and was very concise with the solution
LVL 44

Expert Comment

ID: 34897727
Thanks, glad to help

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
This article will show a step by step guide on how to mask column values in Oracle 12c using DBMS_REDACT full redaction option. This option is available on licensed Oracle Enterprise edition as part of Oracle's Advanced Security.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

585 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question