I am trying to automatically write the maximum (and minimum) value of a specific layers attribute (a date (or a number)) in qgis print composer.

I'm trying to do this for an automatically updated map and its title should automatically get the time range of events (for example "Earthquakes from 07/2016 to 09/2017"). Date of each event is stored in the attribute table of a layer (*.csv). Also each event has an ID starting by the oldest event (so max/min id would work as well). (Goal of all this is that users only need to press "export pdf" and nothing else)

Was trying to combine "attribute", "maximum", "get_feature" and "layer_property" in query builder in different ways. While it was no problem to do in attribute tables I wasnt able to figure out how it could work in print composer. Minimum works pretty simple this way


So far I unfortunately have no experience with phyton.

Any ideas about this?

1 Answer 1


A very easy workaround is to create a virtual layer. Something like:

select max(testing) as ma, min(testing) as mi from test

and use that layer

  • Works well as long max(attribute name) has no whitespace in it. If there is one it always throws back the first feature. Tried max(attribute name), max('attribute name'), max("attribute name") and max([attribute name]). Any suggestions?
    – MrXsquared
    Oct 18, 2017 at 19:14
  • So, the problem is that the attribute value had white spaces in it, did I understand correctly? If so, can you simply use max(trim(attribute_name))? it uses SQLite syntax, so you can do all the data tricks it offers :) Oct 18, 2017 at 22:50
  • no, the field name (or attribute name) has whitespaces. For example: [Fi eld name1] - [Fieldname2] - [Field na me 3] value1 - val ue 2 - value3
    – MrXsquared
    Oct 19, 2017 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.