Here's a case of what NOT to do and what TO do...
Lets say, for example, you have the following that Fred the-brilliant-sales-guy-and-aspiring-engineer built as a formula:
OR(
AND(
fieldXYZ > 10,
CONTAINS(fieldABC, 'example1'),
field123 = 'just another case'
),
AND(
fieldXYZ = 5,
CONTAINS(fieldABC, 'example1'),
field123 = 'just another case'
),
AND(
fieldXYZ < 3,
CONTAINS(fieldABC, 'example1'),
field123 = 'just another case'
)
)
Ever see something like that? Its probably cleaner than the average salesperson would develop after all check out that indentation - classic good geek practice for readability. However thats not much of the crux here. Note the only difference between the multiple nested AND groups is the criteria on fieldXYZ otherwise each is the same test. This is redundant and can quickly become more so as new criteria might need to be added.
The simplification that works is the following:
AND(
OR(
fieldXYZ > 10,
fieldXYZ = 5,
fieldXYZ < 3
),
CONTAINS(fieldABC, 'example1'),
field123 = 'just another case'
)
Thats it! Isnt that better? Essentially we need to think of the overarching AND instead of an overarching OR and reverse those then add the OR inside that expresses what was different about each original AND group.
This is a simple case but it applies to any similar situation where you have repeating AND group criteria inside an outer OR group.
Carry on and keep it clean and manageable folks!
),
CONTAINS(fieldABC, 'example1'),
field123 = 'just another case'
)
Thats it! Isnt that better? Essentially we need to think of the overarching AND instead of an overarching OR and reverse those then add the OR inside that expresses what was different about each original AND group.
This is a simple case but it applies to any similar situation where you have repeating AND group criteria inside an outer OR group.
Carry on and keep it clean and manageable folks!
No comments:
Post a Comment