I am trying to wrap a get_feature with an attribute expression to perform the equivalent of a VLOOKUP in Excel. Using the form below I get a NULL result.

attribute(get_feature('pointst', 'when', maximum('when')), 'Number')
  • 'When' is a timestamp
  • 'pointst' is the current layer
  • 'Number' is an integer

1 Answer 1


You need to use double quotes for the field "when" in maximum():


The reason is that single quotes indicate a string. The maximum of a string is not possible. Double quotes refer to fields in QGIS. If a fieldname has no special characters / whitespaces, it also accepts it without any quotes. Some functions though require the field or layername given as string, such as attribute() and get_feature(). I assume this has to do with the way functions (or better the code behind these functions) can work with a referenced layer or relation. You usually reference fields by single quotes in functions where you can use different layers or relations.

  • I have this working using the double quotes - any explanation of why?
    – Sethinacan
    Jul 25, 2023 at 12:57
  • reading your answer, it is quite familiar and I should have remembered but in my defence if you use the expression builder it adds double quotes for fields from the current layer and single for fields from other layers
    – Sethinacan
    Jul 25, 2023 at 14:18
  • Just in case it's not clear, you don't need to defend yourself @Sethinacan. This is an unintuitive nuance of the query language a common mistake to make.
    – Paul H
    Jul 25, 2023 at 21:44

Your Answer

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

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