I am trying to evaluate three attribute fields and return a different value. When I try this expression I get no return.

WHEN (Att_A =1) AND (Att_B = 2) AND (Att_C = 3) THEN 40

When I try it with 2 I get a return.

WHEN (Att_B = 2) AND (Att_C = 3) THEN 40

Can you not evaluate three items in a case statement in QGIS or am I doing something wrong?

  • And you definitely have data that satisfies the criteria (Att_A =1) AND (Att_B = 2) AND (Att_C = 3) ? Try this: CASE WHEN (Att_A =1) AND (Att_B = 2) AND (Att_C = 3) THEN 40 ELSE 999 END Do you get a result now? – M Bain Oct 16 at 22:20
  • Yes there are definitely rows that satisfy those criteria. I think there may be something wrong with my table or QGIS installation because after you implied that it should be possible I tried a simple Att_A =1 Then 40 and it only did some of them. So I tried it on a different table on another computer and the CASE with 2 ANDs worked fine. The field is an integer field that was calculated from other fields. Could it be corrupted some how? – Baswein Oct 16 at 22:50
  • 6
    I think I figured it out. Even though it is an integer field type and the values are shown as integers if in the field calculator I load the values from the field they show as decimals. I think this is because I created them by division they still contain the decimals. If I do "to_int" then the formula works. This seems like a bug. – Baswein Oct 17 at 1:44
  • 1
    Nice work. Thanks for the update, does seem like a bug. You may have saved me from bumping up against this in the future. – M Bain Oct 17 at 2:41
  • 2
    As soon as I save the table as a geopackage the integer field takes over and trims the decimals but when it is a temporary table they are decimals. I was chaining a bunch of field creation algorithms together in the Graphical Modeler where they where staying as temporary tables. Thanks for your help. – Baswein Oct 17 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.