I'll try to calculate the minimum value of four different columns in my QGIS table like:
The min. value would be 1,50286 in the first row.
Is there any expression or tool to find the minimum value and write it into a new field?
-
1Please create a real table, or provide a screenshot, because currently 1 would be the min. value.Erik– Erik2019年05月21日 10:58:53 +00:00Commented May 21, 2019 at 10:58
2 Answers 2
Simply use Field Calculator
and create new field with
min(A,B,C)
where A, B, C, are field names
If you need to keep the field (min_ABC
) updated, set the expression to default value of the field. It can be done in Attributes Form setting in Layer Properties. Scroll down in the right part of window fill the default value and check Apply default value on update. Than it will automatically update when you change the values, and also works on new features.
Notice that this will work only on update not if you fill the values in the process of creating feature.
-
1Just a small extension, in case, if you need to find a min value within all values (not only for a row/column), then just use
minimum(min(A,B,C))
2019年05月23日 05:13:56 +00:00Commented May 23, 2019 at 5:13
In case you do not want to modify your original data then I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in 'layer' with three values accordingly, see the image below.
With the following query, it is possible to achieve the result
SELECT l.*, MIN(l.Value1, l.Value2, l.Value3) AS MIN_VALUE
FROM layer AS l
GROUP BY l.id
The output Virtual Layer will maintain initial attributes and geometries and an additional field "MIN_VALUE"
.
-
1Good suggestion, but keep in mind that virtual field is stored in the project not in the data. You can export the data, than the virtual field is converted to "non-virtual".Oto Kaláb– Oto Kaláb2019年05月23日 07:44:45 +00:00Commented May 23, 2019 at 7:44
-
Truly agree with you. Thank you for a hint2019年05月23日 07:45:39 +00:00Commented May 23, 2019 at 7:45
Explore related questions
See similar questions with these tags.