# Adding certain number for each community with QGIS field calculator?

I have a big data with the parcel numbers of different communities. Now I want to join the parcel numbers of the attribute list with an excel table. Since they need to have something in common to realize the join, I have to get the parcel numbers into the same structure like the excel table.

The parcel number of the attribute list look for example like this: [803, 1] In my excel table I created the same structure, but since there might be the same number in different communities, I had to separate them, that’s why I choose to use another number for each community. For example: [803, 1]_1 (1 for community A) , [803, 1]_2 (2 for community B).

The problem is that I don´t know how to create this formula in my attribute table without having to edit each parcel number. Is there a formula to use? In the attribute table I have the parcel number like this [803, 1] and also the community number like this [08, 8030]. I add a picture of my attribute table, so I think its easier to understand what I need.

Is there a formula that says for example something like this: when in “Gemarkung” [08, 8030], then in “Flurstueck” [621, 4]_1 and when in “Gemarkung” [08, 8015], then in “Flurstueck” [195, ]_2 (of course in "Flurstueck should be the same number and just add _2 or _1...) I hope I could explain myself with what I need.

I am using QGIS version 2.12.3 Lyon.

Depending on if you have a reasonably small amount of communities, you could use something like the following by going to the Field Calculator and selecting to either create a new field or update "Flurstueck":

CASE
WHEN "Gemarkung" = '[08, 8030]' THEN "Flurstueck" + '_1'
WHEN "Gemarkung" = '[08, 8015]' THEN "Flurstueck" + '_2'
ELSE "Flurstueck"
END


If you have a quite a large amount of communities then you should probably edit your question to include more details such as the number of communities you have, if they follow a pattern in their attributes etc.

• Thats perfect! thank you so much! Its amazing what QGIS can do with the right formula...! Jun 7, 2016 at 8:31
• @user69896 - Most welcome! Yup, took me a while to understand how the SQL-based formulas worked ;) Jun 7, 2016 at 9:00