### Title

Simpler calculation possible? (Case with multiple conditions)

### Post

Edit:Solution I used to solve this issue is down at (what is currently) the bottom of this thread.

Hi All,

I have a calculation for a category ID field set to automatically enter either two values, or one or the other of the two.

Simplified, what I'm currently doing is as follows:

case(x=true and y=true;result 1;

x=true and y=false;result 2;

x=false and y=true;result3;

default result)

The calculation is manageable as is but if I want to add more variables it could get unwieldy pretty fast. Is there a simpler way to do this? Below is the actual calculation.

Case(

(PatternCount ( Self;"38")=0 or IsEmpty(contactCategoryID))and (not IsEmpty(Contacts_Assign Contact Category If Distro Vendor_INVENTORY::vendorID) and PatternCount(Self;"27")=0);"38¶27¶"&contactCategoryID;

(PatternCount ( Self;"38")=0 or IsEmpty(contactCategoryID))and (not IsEmpty(Contacts_Assign Contact Category If Distro Vendor_INVENTORY::vendorID) and PatternCount(Self;"27") > 0);"38¶"&contactCategoryID;

(PatternCount ( Self;"38") > 0 or IsEmpty(contactCategoryID))and (not IsEmpty(Contacts_Assign Contact Category If Distro Vendor_INVENTORY::vendorID) and PatternCount(Self;"27")=0);"27¶"&contactCategoryID;

Self)

For starters, I'd change the order of the boolean expressions. Case branches on the first true so if PatternCount doesn't return a value greater than zero, it must return zero.

You can also use the Let function to clean up your expressions when you have the same sub expression used more than once.

Let ( [ pc38 = PatternCount ( self ; "38" ) ;

pc27 = PatternCount(Self;"27");

EmCat = IsEmpty (ContactCategoryID) ;

EmpCont = IsEmpty(Contacts_Assign Contact Category If Distro Vendor_INVENTORY::vendorID)

]

Case ( ( pc38 > 0 or EmCat ) and not EmpCont and not pc27 ; "27¶"&contactCategoryID ;

EmCat and not EmpCont and not pc27 ; "38¶"&contactCategoryID ;

not EmpCont ; );"38¶27¶"&contactCategoryID;

Self

) //case

) // Let

That's just a first cut, additional simplification may be possible. If I were looking at your complete set up and understood why you want to build this list, a completely different approach that avoids this complicated auto-enter calc might be possible.