I need to identify the majority of a string in an attribute field. For example 'A,AB,C,A' -> 'A'
Since QGIS 3.18 the function array_majority()
is available.
However, I use the latest stable version 3.16 and I am wondering if something similar can be done?
Something like:
array_to_string(majority(string_to_array("sumEHZ")))
Best Answer
In QGIS 3.16, you can use this expression, where
text
is the field containing the text you want to replace:Expression edited, the repeating part from the initial expression is created as a variable
var
and called twice witheval(@var)
to make the expression a bit shorter. See the screenshot for the (otherwise unchanged) initial expression: