In the following code, my dataset is {1,2,3,4}.

With no filter, DTLiffirstrow will return true at "1" and DTLiflastrow will return true at "4". This is what I expect from these functions.

When I filter the dataset to {2,3}, DTLiffisrtrow returns true at "2". Perfect.

But DTLiflastrow is always false. I would expect it to return true for the value "3".







How could I detect the last row of a filtered set of data?

  • There's no way for datatool to know it's on the last filtered row on a single pass. It would require two passes: first to find out which is the last row of the filtered set and the second to compare the current row with that value. (datatool knows how many rows the database has but the last row may be filtered. \DTLiflastrow can only compare the current row index with the total number of rows.) – Nicola Talbot Apr 1 at 15:23

This is not a bug, it's a feature !

See the doc (datatool-code.pdf, around page 199):

\DTLiflastrow{〈true part 〉}{〈false part 〉}

Checks if the current row is the last row of the database. It doesn’t take the condition (the optional argument of \DTLforeach) into account, so its possible it may never do 〈true part〉, as the last row of the database may not meet the condition.

It is therefore not very useful and is confusing since it behaves differently to \DTLiffirstrow which does take the condition ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.