• IIF statement syntax (2003)

    Author
    Topic
    #446363

    I have a query where I am comparing two tables – Augdata and Sepdata. I join the tables by a unique Id. The fields I am comparing have Y and N in them. Two fields I am comparing are SepHealth and AugHealth. I want a third column that I will call GAin/Loss/No Change. I want an IIF statement that says – IIF SepHealth = AugHealth then “No Change” else iif SepHealth = Y and AugHealth = N, “Gain” else iif SepHealth = N and AugHealth = Y, “Loss”. Can someone help me with the correct syntax for my Gain/Loss/No Change column?

    Viewing 0 reply threads
    Author
    Replies
    • #1085024

      Try this:

      =IIf([SepHealth]=[AugHealth],"No Change",IIf([SepHealth]="Y" And [AugHealth]="N","Gain","Loss"))

      This assumes that there are no blanks.

      • #1085025

        What if there are blanks. I am home so I am not sure about the data. How would I account for blanks?

        • #1085028

          What do you want to return if

          1) AugHealth = Y and SepHealth is blank
          2) AugHealth = N and SepHealth is blank
          3) AugHealth is blank and SepHealth = Y
          4) AugHealth is blank and SepHealth = N
          5) AugHealth and SepHealth are both blank

          • #1085029

            1) AugHealth = Y and SepHealth is blank – Loss
            2) AugHealth = N and SepHealth is blank – Loss
            3) AugHealth is blank and SepHealth = Y – Gain
            4) AugHealth is blank and SepHealth = N – Loss
            5) AugHealth and SepHealth are both blank – No change

            • #1085030

              Let’s see. Try this expression:

              IIf(IsNull([AugHealth]) And IsNull([SepHealth]) Or [AugHealth]=[SepHealth],"No Change",IIf([SepHealth]="Y","Gain","Loss"))

              evilgrin

            • #1085031

              Thanks Hans – I will let you tomorrow if it works.

    Viewing 0 reply threads
    Reply To: IIF statement syntax (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: