Overview
Problem
If you directly use the seq() function, sequence numbers on one page are increased based on the sequence numbers on the previous page. As shown in the following figure, the last sequence number is 54 on the first page, and the first sequence number is 55 on the second page.
When can you do if you want to start the sequence number from 1 on each page during report pagination preview? The effect is shown in the following figure.
Solution
Although original sequence numbers are incremental, each row has a unique sequence number. Based on original sequence numbers, you can start sequence numbers on each page from 1 by determining the position of the current sequence number on this page.
Example
Data Preparation
Create a template and create a new data query through SELECT * FROM OrderDetails_new.
Report Design
(1) Drag fields to corresponding cells, insert the formula seq() into cell A2, set Left Parent Cell to B2 for cell A2, and select Repeat Title Row for the first row.
(2) Insert another sequence number column next to the sequence number column, insert the formula if(COUNT({A2})=1,1,inarray(A2,{A2})) into cell B2, and set Left Parent Cell to C2 for cell B2. In the formula, {A2} obtains all the values expanded from cell A2 on the current page. If only one value is obtained after expansion, the result is 1. Otherwise, the result is the current position of cell A2's value in the {A2} array. If only one row exists on a page, {A2} obtains a value that will not be processed as an array. The second parameter in inarray must be an array, which requires judgment.
(3) Set Left Parent Cell to None for cell C2, and hide column A, as shown in the following figure.
Effect Preview
PC
Save the template and click Pagination Preview. The effect is the same as that shown in section "Problem."
Mobile Terminal
The preview effect on the app/HTML5 terminal is the same, as shown in the following figure.
Template Download
For details, you can click to download Restarting Sequence Number Generation on Each Page.cpt.