I ran into this myself as well, with a Hierarchical Viewer that was pulling FAQ page types nested inside of folders. What I was able to do in the transformation was reference the parent folder & count the FAQ children. The reason I took this approach was that I wasn't looking for the last child, but rather, a ratio to break up the content (e.g. 1/2, 1/3 etc). I also used NodeOrder instead of DataItemIndex because of the hierarchy.
{%
if(Documents[NodeAliasPath].NodeOrder = Ceiling((Documents[NodeAliasPath].Parent.Children.Count/3)) ) {
//code here to close a div & start a new one
}
|(identity)GlobalAdministrator%}