# Concatenate Fields into One Field in QGIS

I have seen some posts on this, but only for ArcMap. I am looking to take a range of values from two fields and concatenate them into one field to make a unique value. For example:

``````XMAX     YMAX       GRIDID
332500   5366000    33255366
333000   5366000    33305366
``````

In ArcMap you can do something like `(Mid([XMAX]),1,4)+(Mid([YMAX]),1,4)`.

I know this can be done in a PostGIS database, but for the moment it needs to be done on a shapefile and I am looking to use QGIS.

Thanks

-
Are "XMAX" and "YMAX" actually string fields or are they really numeric? – whuber Jun 22 '12 at 15:47
They are numbers. But I converted the number values to string in new columns and the calculation Jef supplied still didn't work. – Ryan Garnett Jun 22 '12 at 15:50
Why not just combine them numerically then? The simplest example assumes all values of "XMAX" are six-digit multiples of 100 and all values of "YMAX" are seven-digit multiples of 1000: "XMAX"*100+"YMAX"/1000 does the trick. More generally you may need to do some rounding of the values before carrying out this calculation. – whuber Jun 22 '12 at 15:54
Thank you Whuber, that totally did it. Thanks! – Ryan Garnett Jun 22 '12 at 17:06

In QGIS it's almost the same: `substr("XMAX",1,4)||substr("YMAX",1,4)` in the field calculator.
Hm, works for me in 1.8. If you are using an earlier version try: `substr(tostring("XMAX"),1,4)||substr(tostring("YMAX"),1,4)` – jef Jun 22 '12 at 15:51
no, `xmax`, `ymax` and `gridid` are whole numbers - but the conversions should happen transparently. But I think the expression engine was completely redone in 1.8, so ymmv with 1.7. `toint(...)` should still help there. – jef Jun 22 '12 at 17:35