Bypass conditions with another condition (1 Viewer)

Mackbear

Registered User.
Local time
Yesterday, 19:15
Joined
Apr 2, 2019
Messages
168
Hello everyone, good day! I hope you're all doing fine.

So I have this formula because of your help guys and I need to add another condition that will ignore these conditions if the condition is met.
This one determines the priority based on Age, however I need to have it ignore this based on a content of a different field not on Age. I don't know how to structure it... hope you can help me

IIf([Age]<=-2,"Emergency",IIf([Age]<=0,"Critical",IIf([Age]<=2,"High",IIf([Age]<=5,"Medium",IIf([Age]>=6,"Low","No Date")))))

Thank you everyone in advance!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:15
Joined
Feb 19, 2013
Messages
16,553
I presume this is in a query, not part of vba code?

just put the other condition first - but the iif function needs to return something, even if it is a "" or null

iif(othercondition=true,"",iif([Age]<=-2,"Emergency.........
 

isladogs

MVP / VIP
Local time
Today, 00:15
Joined
Jan 14, 2017
Messages
18,186
Just out of interest how can Age ever be a minus value such as -2?
 

Mackbear

Registered User.
Local time
Yesterday, 19:15
Joined
Apr 2, 2019
Messages
168
Just out of interest how can Age ever be a minus value such as -2?

Hello, it is just the amount of days that it is already past, it is calculated based on a date, if it is -2 then it is 2 days past due. :)
 

Mackbear

Registered User.
Local time
Yesterday, 19:15
Joined
Apr 2, 2019
Messages
168
I presume this is in a query, not part of vba code?

just put the other condition first - but the iif function needs to return something, even if it is a "" or null

iif(othercondition=true,"",iif([Age]<=-2,"Emergency.........

Thank you very much for helping out a beginner... thank you!
 

Mackbear

Registered User.
Local time
Yesterday, 19:15
Joined
Apr 2, 2019
Messages
168
I presume this is in a query, not part of vba code?

just put the other condition first - but the iif function needs to return something, even if it is a "" or null

iif(othercondition=true,"",iif([Age]<=-2,"Emergency.........

Thank you this worked. Thank you for helping a beginner :):):)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:15
Joined
Oct 29, 2018
Messages
21,358
Thank you this worked. Thank you for helping a beginner :):):)
Hi. Just as FYI, what you're doing now can be called "Nesting." This is a very common practice. You sometimes need to "nest" several functions or expressions to modify the outcome of a simple expression. For example, let's say you have a start date and you want to know how many days before its anniversary date. You might try something like this:
Code:
DateDiff("d",Date(),DateAdd("yyyy",1,[StartDate]))
What that code is doing is add 12 months (1 year) to the "start date" to get the anniversay date. Then, it compares the resulting anniversary date to today's date to get the number of days remaining.


Good luck with your project.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:15
Joined
Feb 19, 2013
Messages
16,553
something else to be aware of - the iif function when used is a query only needs to return the true part (the first option). However in VBA it needs to return both.

If a value is not returned then it will have a 'value' of null. Whether this matters or not to you depends on what you are doing with the data. So I could have said

iif(othercondition<>true, iif([Age]<=-2,"Emergency.........
 

Mackbear

Registered User.
Local time
Yesterday, 19:15
Joined
Apr 2, 2019
Messages
168
something else to be aware of - the iif function when used is a query only needs to return the true part (the first option). However in VBA it needs to return both.

If a value is not returned then it will have a 'value' of null. Whether this matters or not to you depends on what you are doing with the data. So I could have said

iif(othercondition<>true, iif([Age]<=-2,"Emergency.........

Thanks it would have been any of the conditions if the first condition is not true... ;)
 

Users who are viewing this thread

Top Bottom