I have features with 3 columns of information ("material", "name", "dimension") in the Attribute table. I need these features to group - to create 4th column where features with same "material", "name" and "dimension" have a new unique code. I need to do it in QGIS. How can be it done?


And since you say "unique code" you can use a rich set of hashing functions (in the Field Calculator), e.g.

hash( concat( "material", "name", "dimension" ), 'md4' )

Just for reference, a smarty-hacky way to get unique integers directly from an Expression:

array_find( array_distinct( array_agg( concat( "material", "name", "dimension" ) ) ), concat( "material", "name", "dimension" ) )

You can use the Field calculator : enter image description here

It open a modal that will help you create a new field (=column) based on a formula.

There is many option you can use to group different attribute together. I suggest you use a concatenation of your 3 fields to make a new one. You can do it whith the formula :

"material" || "name" || "dimension"

The name of your field in the layer could be integrated easily in the formula by double clicking in the help (see picture below). enter image description here

If you want you can add some text to separate your field, here is separated with -.

"material" ||'-'|| "name" ||'-'|| "dimension"

You have to choose an output field type that will be Text (string). To save this there is two option :

  1. if you want this field to be always calculated and updated based on the values of the 3 other fields then choose to Create virtual field.
  2. if you want to calculate once the value of the field then select Create a new field and do not check Create virtual field.

Note : there is many option to pre process your field content if you want to take only the first two letter of each field or any other thing. Check the help to find what could be usefull.


Try "Add autoincremental field", that includes an option with grouping field(s).

Your Answer

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

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