Field Calculator: using the x- or yat or (0 "or-1" ) expression, I keep receiving an error:

An error occurred while evaluating the calculation string: Index is out of range.

I have shut down and restarted a few times, sometimes the error does not return.

Why is this happening and what can I do to fix it?

  • What version of QGIS are you using? Does this happen to all datasets or just a single table?
    – Jakob
    Jan 29, 2014 at 12:18
  • Are you using the function on line features?
    – underdark
    Jan 29, 2014 at 19:46
  • Hi. That is an affirmative, Underdark. I am using it on a line vector dataset. It has been working fine for a while now, even on larger datasets, but tried a few smaller sets yesterday and i kept getting this result. Dont know if this is also related, but if I edited these same data sets, editing meaning using the merge and cut tools, i would get errors or attribute records for non-existent lines.
    – VeM
    Jan 30, 2014 at 7:46

1 Answer 1


This could be the solution to your issue.
My line dataset had lines dissolved by an attribute, so that two (or more) lines in separate locations were merged (the dissolve command has an option for this or the merge command may have been used) to a single record of the attribute table.


Merge record

Merge Command


When editing the vertices of such a record you can see the multiparts.


When you define the starting vertex (xat(0), yat(0)) of the line there are actually two. I think that this is where the error originates from.

A way to avoid this is to use the 'Explode lines' tool from the processing toolbox (from the "Processing" plugin) or the explode tool from the edit toolbar.
Edit Toolbar
This will create a new record in your attribute table for every line segment meaning there is only one start and end vertex for each record. I used this on my line dataset and the x- or yat or (0 "or-1" ) expressions worked without error.

After your calculations you can dissolve your lines again using any of the dissolve functions from the processing toolbox.

  • 2
    wasn't the question about QGIS?
    – MrXsquared
    Jul 7, 2019 at 20:56

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.