This question already has an answer here:

I have attempted to write an expression for hours now by looking through these forums.

I want to write if this column equals Blank, than this column equals blank. Ex) If defect_typ = A_FC THEN Defect_Nam = Fatigue Cracking

I can get a return from multiple codes, but here is an example of one I did:

CASE WHEN defect_typ LIKE '%A_FC%'
       THEN 'Fatigue Cracking' ELSE 'other'

No matter what code I use it fills my entire defect_nam column with Fatigue Cracking or other, and if I try to do multiple, (which I need to create multiple conditional rules) it will fill the column with a mash up of the returns (fatigueCrackingBlockcrackingPatching) but I need to figure out how to do one before I can move on.

I am an ArcMap Vet and to get the result I want in Esri I would use the following script

def Defect(defect_types_code):    
    if (defect_types_code == "A_LC"):
      return "Linear Cracking"  
    elif (defect_types_code == "M_PS"):
        return "Parking Bumper Damage"
    elif (defect_types_code == "M_RB"):
        return "Rebuild/Replace Catch Basin"
    elif (defect_types_code == "M_RD"):
        return "Ramp Damage
      return "N/A"  

How do I write this in QGIS?

I was linked to another question with answers to help, "Elseif Conditional Statement in QGIS Field Calculator,"but the outcome of this code filled my defect_nam with all Nulls.

marked as duplicate by Andre Silva, Community Jul 31 '18 at 19:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Welcome to GIS:SE @Amandalehew! Try If("defect_typ" LIKE '%A_FC%', 'Fatigue Cracking', 'other'). – Joseph Jul 31 '18 at 15:20
  • @Joseph That worked!! Now, how do I do multiple? ("defect_typ" LIKE '%A_FC%', 'Fatigue Cracking', 'other') + ("defect_typ" LIKE '%A_BC%', 'Block Cracking', 'other') ?? – Amanda lehew Jul 31 '18 at 15:38