I want to make a rule-based style on the maximum value from a field. I set my expression like:


It returns every value instead of only the maximum one.

Can anyone tell me the right syntax for this?


Since QGIS 2.16 there is now an inbuilt way to calculate the maximum value for a whole layer:


This will return the largest value in the 'fieldname' column for the layer.


The max function doesn't operate across features, just values passed to the function. Eg


Will return 5. There's no function currently available which calculates the maximum value for an attribute across the entire layer.

  • I have a feeling that there must be a function for this available meanwhile ;) – Matthias Kuhn Jan 23 '17 at 13:50

This code, in Python Console of QGIS, returns maximum value of field whose index is 3: 'AREA' (shapefile used: world_borders.zip):

layer = iface.activeLayer()
id_att_list = layer.pendingAllAttributesList()

print id_att_list #list of attributes index

for item in id_att_list:
    #index and field names
    print item,layer.attributeDisplayName(item)

#maximum value for field whose index is 3 (AREA)
area_max = layer.maximumValue(3)

print "maximum area = ", area_max

enter image description here

  • I am not familiar with python. How do I implement this into the rule-based-style? – PieterB Mar 12 '15 at 8:39

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.