Link to home
Start Free TrialLog in
Avatar of databarracks

asked on

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

Avatar of databarracks


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.
Avatar of Scott McDaniel (EE MVE )
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.
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.
Could someone please help?
Avatar of GRayL
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Spot on with the recommendation and was very concise with the solution
Thanks, glad to help