4

I have a field of currency values in an attribute table. As an example, I'm attempting to replace £10,000.00 to 10000.00 so QGIS can run graduated styles on the new field. The following replaces the £ sign with a blank character.

replace(  "field_name", '£', '')

I'm struggling to get rid of the comma in the same expression. I have tried:

replace(  "field_name", '£', '') || replace(  "field_name", ',', '')

but this returns 10,000.00£10000.00

The 'replace' expression doesn't seem to cater for more than one character to target as a replacement. Do I need to do this over 2 expressions?

7

You need to use a nested replace() function such as

replace(replace('£10,000.00','£',''),',','')

You can nest as many replace() as you want.

| improve this answer | |
7

You can do both replacements using a single function call:

1) using regex_replace, where you would look for the two characters of interest (inside square brackets):

regexp_replace("field_name",'[£,]','')

or 2) the map variant of replace, where the map is a series of key-value, the key being the string being searched for and the value being the replacement string

replace("field_name",map('£','',',',''))
| improve this answer | |

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.