I am doing a lab worksheet and I am having a hard time figuring out what to put in in the expression box.

GENERAL STEP: You need to identify Aspen and Birch (Select by Expression) and export these stands to a separate shapefile, naming it something like AspenBirch.shp. Then open the AspenBirch attribute table and alternately select the young, intermediate, or old tree stands, exporting each to create three new shapefiles.

Out of the 506 Vegetation records, 111 are Aspen or Birch. Of these:

  • 30 records are Young; less than 18 year, from 2006 through 1988
  • 25 records are Intermediate; between 19-34 years, from 1987 through 1972
  • 30 records are Old; 34 years and over, from 1971 to 1888.

Below is the attribute table data that the records are in. I am a beginner QGIS user so I am still learning how to come up with the correct valid expressions.

enter image description here

UPDATE: I have entered in the adjusted expression in the field calculator like in the answer reply but under my Category all it shows is NULL values. I may have made a small mistake but I can't tell since the expression doesn't show anything invalid.enter image description here

  • 3
    Can you please share what statements you have tried? It appears the ORIGIN field is not a numerical data type, but instead a string data type.
    – evv_gis
    Apr 10, 2023 at 15:39

1 Answer 1


To resume your question: you need 6 new vector files (2*3): for each Cover_type (Aspen and Birch) one for each of three age categories.

Instead of doing it one by one, I advice to do it at once by categorizing your features and then split the layer (based on these categories) in 6 layers containing subsets of the initial data. As your ORIGIN field contains years in string (text) format, you have to convert them to integers using to_int():

  1. Categorize your values: create a new field called category using field calculator with this expression based on case ... when condition and concatenate ORIGIN and Cover_Type using pipes operator || :

         when to_int(ORIGIN) >= 1988 then 'young'
         when to_int(ORIGIN) <= 1987 and to_int(ORIGIN) >=1972 then 'intermediate'
         when  to_int(ORIGIN) < 1972 then 'Old'
     end || '_'  || 
         when Cover_Type ='Birch' then 'Birch'
         when Cover_Type = 'Aspen' then 'Aspen'
  2. Run Menu Processing > Toolbox > Split vector layer and use the category field created as input for Unique ID field.

You're done.

By the way: Is there a reason you want to save as shapefile? Geopackage would be a good alternative.

Step 1: enter image description here

Step 2: enter image description here

  • Yes, thank you appreciated. Apologies for the inconsistencies, my lab instructions tell me that I need to identify the Aspen & Birch stands under the 3 conditions and filter them regarding by the years and to make them into 3 new shapefiles.
    – Jamie
    Apr 10, 2023 at 17:01
  • I have an issue after I enter in the expression in the field calculator and under Category it shows as NULL for every value so I'm unsure what I'm doing wrong. I changed the original data to integer from text string and under Category it still shows NULL values.
    – Jamie
    Apr 10, 2023 at 18:06
  • You must adapt the expression to the field values you have. If it doesn't work, post a screenshot showing the same as my first screenshot
    – Babel
    Apr 10, 2023 at 18:29
  • Screenshot posted. I'm not sure what I did that's causing it to show NULL values
    – Jamie
    Apr 10, 2023 at 18:53
  • 2
    You're welcome. As a new user, please be adviced that the policy of this site is to avoid "thank you" messages. Instead, it encourages you to accept the answer if it solved the problem and/or upvote it if you found it helpful: click the checkmark right to the answer to accept it - see: gis.stackexchange.com/help/someone-answers Just click the checkmark, see here: meta.stackexchange.com/questions/5234/…
    – Babel
    Apr 10, 2023 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.