If Statement

Hello,

Is it possible to write an IF statement that has two requirements in order for the statement to be true? Secondly, how can I have the second requirement be based on if the point is blank ( have it ="" or =" ")?

Thanks.

Parents
  • Yes, you can combine two conditional expressions with either "AND" or "OR". Which one you use depends if you want both to be met or just one or the other.

    For example:

    <<IIf(_
      <<HasData(<<MY TABLE.Field 1>>)>> And _
      <<HasData(<<MY TABLE.Field 2>>)>>,_
      ABC,_
      XYZ_
    )>>

     

    For your second question, it depends somewhat on what the field contains. Is it a numeric only field and you are testing to see if it is blank? Or, is it a text field and you are testing to see if it is blank? 

    For example:

    <<IIf(_
      <<IsNumeric(<<SAMPLE.Blows 2nd>>)>> And _
      <<IsNumeric(<<SAMPLE.Blows 3rd>>)>>,_
      <<Calc(_
        <<SAMPLE.Blows 2nd>> + _
        <<SAMPLE.Blows 3rd>>_
      )>>,_
      <<FirstData(_
        <<SAMPLE.Blows 3rd>>,_
        <<SAMPLE.Blows 2nd>>,_
        <<SAMPLE.Blows 1st>>_
      )>>_
    )>>

    Here, we are testing to see if "both" the Blows 2nd and Blows 3rd fields have values. If either one is blank, then the IIf function will return the "false" argument.

     

    You could do the following to return a "true" argument when a numeric field is blank:

    <<IIf(Not <<IsNumeric(<<expression>>)>>,xxx)>>

    or

    <<IIf(Not <<HasData(<<expression>>)>>,xxx)>>

     

    Here is another example: (where we are checking to see if there is a value in the "Refusal Penetration" field AND the Blows 4th field is blank.

    <<IIf(_
      <<HasData(<<SAMPLE.Refusal Penetration>>)>> And _
      (Not <<HasData(<<SAMPLE.Blows 4th>>)>>),_
      <<FirstData(_
        <<SAMPLE.Blows 3rd>>,_
        <<SAMPLE.Blows 2nd>>,_
        <<SAMPLE.Blows 1st>>_
      )>>_
      <<DelimitData(/,<<SAMPLE.Refusal Penetration>>)>>,_
      <<Calc(_
        <<SAMPLE.Blows 2nd>> + _
        <<SAMPLE.Blows 3rd>>_
      )>>_
    )>>

Reply
  • Yes, you can combine two conditional expressions with either "AND" or "OR". Which one you use depends if you want both to be met or just one or the other.

    For example:

    <<IIf(_
      <<HasData(<<MY TABLE.Field 1>>)>> And _
      <<HasData(<<MY TABLE.Field 2>>)>>,_
      ABC,_
      XYZ_
    )>>

     

    For your second question, it depends somewhat on what the field contains. Is it a numeric only field and you are testing to see if it is blank? Or, is it a text field and you are testing to see if it is blank? 

    For example:

    <<IIf(_
      <<IsNumeric(<<SAMPLE.Blows 2nd>>)>> And _
      <<IsNumeric(<<SAMPLE.Blows 3rd>>)>>,_
      <<Calc(_
        <<SAMPLE.Blows 2nd>> + _
        <<SAMPLE.Blows 3rd>>_
      )>>,_
      <<FirstData(_
        <<SAMPLE.Blows 3rd>>,_
        <<SAMPLE.Blows 2nd>>,_
        <<SAMPLE.Blows 1st>>_
      )>>_
    )>>

    Here, we are testing to see if "both" the Blows 2nd and Blows 3rd fields have values. If either one is blank, then the IIf function will return the "false" argument.

     

    You could do the following to return a "true" argument when a numeric field is blank:

    <<IIf(Not <<IsNumeric(<<expression>>)>>,xxx)>>

    or

    <<IIf(Not <<HasData(<<expression>>)>>,xxx)>>

     

    Here is another example: (where we are checking to see if there is a value in the "Refusal Penetration" field AND the Blows 4th field is blank.

    <<IIf(_
      <<HasData(<<SAMPLE.Refusal Penetration>>)>> And _
      (Not <<HasData(<<SAMPLE.Blows 4th>>)>>),_
      <<FirstData(_
        <<SAMPLE.Blows 3rd>>,_
        <<SAMPLE.Blows 2nd>>,_
        <<SAMPLE.Blows 1st>>_
      )>>_
      <<DelimitData(/,<<SAMPLE.Refusal Penetration>>)>>,_
      <<Calc(_
        <<SAMPLE.Blows 2nd>> + _
        <<SAMPLE.Blows 3rd>>_
      )>>_
    )>>

Children
  • I seem to be having an issue when I use an Iif statement with the OR condition. The AND condition works just fine. The statement works when there is only one condition. Also, is it possible to have up to 3 conditions?

    <Iif(_

    <<BASIN FILL.Gravel Size (largest)>>=boulders OR _

    <<BASIN FILL.Gravel Size (largest)>>=cobbles," gravel","")>>

  • Megan, is the field name in BASIN FILL really "Gravel Size (largest)"? Or is that a caption for that field? Also, the condition you are testing against is a text value, so it needs to be delimited with quotes: = "boulders", for example. Finally, the expression also doesn't seem to be complete; there are not enough angle brackets (opening or closing) to balance.

    One thing I would do is to surround the equation arguments in parentheses. SO:

    <<IIf(_
      (<<BASIN FILL.Gravel Size (largest)>>="boulders") OR _
      (<<BASIN FILL.Gravel Size (largest)>>="cobbles"),_
      "gravel",_
      ""_
    )>>

    The above expression tests the contents of the BASIN FILL table field named Gravel Size (largest), and if the content in that field is either "boulders" or "cobbles", the text "gravel" is expressed, otherwise a null text ("") is expressed. (You could also just leave out that final "otherwise" argument.) 

    If the field name is actually "Gravel Size Max", for example, and leaving off the second argument, since nothing is expressed if the condition evaluates to False, the code would be something like:

    <<IIf(_
      (<<BASIN FILL.Gravel Size Max>>="boulders") OR _
      (<<BASIN FILL.Gravel Size Max>>="cobbles"),_
      "gravel"_
    )>>

    I recommend you use the Data Tool to build expressions, which will help avoid typos and mislabeled fields, and also provide syntax and usage clues for the various functions that can be used in gINT expressions. There is a good discussion of this in the Data Tool - Overview topic in gINT Help.



  • Thank you. I copied and pasted it without an angle bracket and the field is actually labelled right. Also, I tried using quotes before. It works now that the condition is surrounded by parenthesis.