2

I have many columns, about 30 and each of those has some attributes. I want to merge those columns to one and collect all attributes in a row of columns. I tried with this post but it is not for I am looking for. Combining Columns QGIS Attribute Table I have an example in ms excel what I want that without commas and spaces. Attributes have to be separated with one comma. enter image description here

With this script, if some fields are empty, I have got null fields. Sorry for my English

enter image description here

  • Have you had a look at the expressions coalesce and try? – Erik Dec 2 '19 at 12:09
  • I used coalesce, but only first attribute was copied – nagib Dec 2 '19 at 12:14
  • Please provide the expression you used. – Erik Dec 2 '19 at 12:15
  • coalesce( "spec" , "spec_1" , "spec_12" , "spec_1_13" , "spec_1_14" , "spec_1_15" , "spec_1_16" , "spec_1_17" , "spec_1_18" , "spec_1_19" , "spec_1_20" , "spec_1_21" , "spec_1_22" , "spec_1_23" , "spec_1_24" , "spec_1_25" , "spec_1_26" , "spec_1_27" , "spec_1_28" , "spec_1_29" , "spec_1_30" , "spec_1_31" , "spec_1_32" , "spec_1_33" , '0') – nagib Dec 2 '19 at 12:42
  • Yeah, and have you read how the expression works? – Erik Dec 2 '19 at 12:43
2

array_filter( map_avals( attributes( )), @element <>'') does the trick.

1/ attributes() get all fields with their corresponding values

2/ map_avals(): gives you just the values as an array

3/ array_filter(array, expression): the expression @element <>'' filters out the empty values

| improve this answer | |
  • With this : array_filter( map_avals( attributes( )), @element <>''), I got empty fields. I forgot to say, some columns are in between that I have to exclude from those columns. I have to pick columns manually, (by hand). Something like the second picture – nagib Dec 2 '19 at 12:02
  • Nice expression! array_to_string( array_filter ... ) converts the array to a string. It works in QGIS 3.10, latest QGIS LTR 3.4.13 doesn't have the attributes() function. – Gabriel De Luca Dec 3 '19 at 1:04

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.