I have made a query that returns data like this: code title date i1.000182 Gate 1 2019-08-22 i1.000182 Gate 2 2019-08-22 i1.000182 Gate 3 2019-08-26 i1.000182 Gate 4 2019-10-01 I1.000156 Gate 4 2020-07-02 i1.000194 Gate 4 2020-01-06 i1.000194 Gate 4 2020-05-31 i1.000090 Gate 4 2020-05-14 For each time a "code" is represented, I need to calculate the datediff between the Gate-dates, e.g.: code title date datediff i1.000182 Gate 1 2019-08-22 0 i1.000182 Gate 2 2019-08-22 0 i1.000182 Gate 3 2019-08-26 4 i1.000182 Gate 4 2019-10-01 36 I1.000191 Gate 3 2019-09-19 0 I1.000191 Gate 4 2020-10-16 393 i1.000194 Gate 4 2020-01-06 0 i1.000194 Gate 4 2020-05-31 146 i1.000090 Gate 4 2020-05-14 0 I know how to compare dates, but can I loop though X times a code is repeated to calculate date? Continue reading...