4D Write Pro: Carry Over Rows are Available!

Using tables in 4D Write Pro documents is more frequent, especially since it is possible to associate a datasource to them, which automatically feeds their rows!

As the number of rows gets more prominent, it is common for these tables to be automatically split into several parts to allow for a page or column break. In this situation, it is sometimes convenient to insert (automatically!) a “subtotal” line at the bottom of each part of the respective tables. Yes, that’s right, this is possible in 4D v19 R7 ?

Demo database

A picture is worth a thousand words.

A picture always beats a long explanation. Here is what we want to obtain:

As you can see, each table part – except the last one – contains an extra row used here to display a subtotal.

This is often necessary, sometimes even legally required, when editing long invoices, for example.

ONE ROW in THE template, AS MANY AS necessary IN THE final document

As mentioned in the introduction, this functionality is available for all tables. Still, it is only considered when tables are associated with a datasource (a collection or a selection of entities). Once this property is activated, the row immediately following the “repeated” row will become the carry-over row.


The activation of this property can be done via the interface…

In both interfaces (toolbar and sidebar), the table menu (  ) contains a new item, “Bottom carry over row.”



… Or by programming

WP SET ATTRIBUTES($table ; wk bottom carry over row ; True | False)


It is essential to understand that this row, unique in the template, will be duplicated as often as necessary once the document is evaluated.

Note that this will not be necessary if the table “fits” in a single block. In this case, the carry-over row will not be represented in the evaluated document.

Otherwise, it will be inserted at the end of every block except the last one. Logically, the last part of the split table should not contain a subtotal but a “Grand Total.” This is why, in the template, the carry-over row is not the last one but is followed by the last rows of the table.


How should the content of the cells in this carry-over row be defined?

As you may have guessed, a new attribute is born: previousItems, which can be used as follow:


This.previousItems returns, depending on the table datasource, either a collection or a selection of entities.

This set contains all the items that have already been evaluated on the current page and the previous ones. You can apply all available functions (min/max/sum/etc.) for collections or entity selections!

Note that if This.previousItems is mainly designed to be used in carry-over rows, its use is not limited to this particular context. It can be used anywhere in the table (except headers) with different values in each context.


This new property makes it possible to get rid of complex code and enrich tables during automatic page jumps.
Enjoy creating lovely templates and avoid complex coding! And as always, your feedback is much appreciated. Join the discussion on the 4D Forum.

More information about carry over rows can be read in the documentation.

Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.