I have a dataset with supplier and its invoices and I need to determinate which of the invoices are consecutives marking it with a 1 or a 0. For example: And what I want is a third column like this: EDIT Thanks for your answers, this options works great, but when I tried it in a real database I realized