LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Cross-fields Multiple-criteria Filtering

    Employee
    Posted 03-02-2015 10:26

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jpstory

    Hi

    I am trying to code something as the below, but got stock with the multiple 'And', 'Or':

    If Field A contains value (1,2,3) AND Field C contains values (a,b)

    Or

    If Field B contains value (1,2,3) AND Field D contains values (a,b)

    Then

    Emit all records meeting the above ceritera


  • 2.  RE: Cross-fields Multiple-criteria Filtering

    Employee
    Posted 03-02-2015 21:56

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Simply use parenthesis:

    emit * 
    where (
    (Field_A==1 or Field_A==2 or Field_A==3) and (Field_C==a or Field_C==b)
    )
    or
    (
    (Field_B==1 or Field_B==2 or Field_B==3) and (Field_D==a or Field_C==d)
    )

    ========
    But, I prefer this, because it tends to be more readable:

    goodrecord=false
    if (Field_A==1 or Field_A==2 or Field_A==3) and (Field_C==a or Field_C==b) then goodrecord=true
    if (Field_B==1 or Field_B==2 or Field_B==3) and (Field_D==a or Field_D==b) then goodrecord=true
    
    emit * where goodrecord==true


  • 3.  RE: Cross-fields Multiple-criteria Filtering

    Employee
    Posted 03-03-2015 07:55

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jpstory

    Thanks stonysmith
    The secord approach is great, just a minor issue, I got more fields and values need to be matched in order to find the goodrecord.
    So instead of listing out all the options, I used regexismatch as below, but it somehow returned the wrong results ( the entire file's reocrds are returned).
    Do you see where I got it wrong ?

     
    goodrecord = false 
    if (str('Field_A').regexismatch("^(1|2|3|4|5|6)$") or str('Field_B').regexismatch("^(1|2|3|4|5|6)$")) and (str('Field_C').regexismatch("^(7|8)$") or str('Field_D').regexismatch("^(7|8)$")) then goodrecord = true
    
    if (str('Field_E').regexismatch("^(1|2|3|4|5|6)$") or str('Field_F').regexismatch("^(1|2|3|4|5|6)$")) and (str('Field_G').regexismatch("^(7|8)$") or str('Field_H').regexismatch("^(7|8)$")) then goodrecord = true
    
    emit * where goodrecord==true


  • 4.  RE: Cross-fields Multiple-criteria Filtering

    Employee
    Posted 03-03-2015 13:43

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jpstory

    It worked, thanks.