I would like to count the number of peaks in a dataset which is saved as a csv file. The data is rainfall values from the last 12 years, saved in 5 min increments and the number of rows involved is well beyond the capabilities of excel.

using excel the following formula does what I am after

=IF(AND(B3>B2,B3>B4), "Peak","")

Is there anyway to replicate this using QGIS field calculator?

Below is an example of the data, I have removed dates and used ID numbers

enter image description here

  • Could you provide two to three rows of data to make answering the question more easier and on point?
    – Erik
    Feb 28, 2019 at 13:23
  • So you want to identify rows whose rainfall value is higher than previous row, and less than following row. Rows are sorted by ID
    – JGH
    Feb 28, 2019 at 13:35
  • Joseph - how would I apply this to the field calculator? would that not mean I would have to type every ID number into the equation? Feb 28, 2019 at 13:36
  • 1
    With a SQL query, you could try to join the table to itself twice, first on ID = ID - 1 and then on ID = ID + 1, then select and update the rows based on your conditions.
    – FSimardGIS
    Feb 28, 2019 at 15:13
  • 1
    Postgres has the lag and lead row accessors in an ordered window.
    – JGH
    Feb 28, 2019 at 16:31


Your Answer

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

Browse other questions tagged or ask your own question.