Sorting order of items in nested table

In Appsheet, I have a table of departments, which links to a table of people in those departments. 

I'm trying to create a report template that lists out the people in each department, grouped by department and sorted by last name.

I want something like:

Department 1

Adams, JoeSmith, JohnZarha, Tim
Day, SaraWright, Julie 

Department 2

Andrews, MaryRega, Tim Smith, John
Bendi, Sue  

 

I have sorted by department and then made a nested table to make the three columns.

<<Start:ORDERBY(SELECT([Related People][WID], MOD([_ROWNUMBER], 3)=1), [Last Name], TRUE)>><<[Last Name]>>, <<[First Name]>>
<<End>>
<<Start:ORDERBY(SELECT([Related People][WID], MOD([_ROWNUMBER], 3)=2), [Last Name], TRUE)>><<[Last Name]>>, <<[First Name]>>
<<End>>
<<Start:ORDERBY(SELECT([Related People][WID], MOD([_ROWNUMBER], 3)=0), [Last Name], TRUE)>><<[Last Name]>>, <<[First Name]>>
<<End>> 

This sorts by the row number of the People table, not the last name. Since the people were not added in alphabetical order I end up with something like this. 

Department 1

Smith, JohnZarha, TimAdams, Joe

Wright, Julie

 Day, Sara

Department 2

Smith, JohnAndrews, MaryRega, Tim
 Bendi, Sue 

All the people are in the right department, but not filling out the columns evenly (and therefore not sorted by last name appropriately).

Is there a way to create a virtual 'rank' column that I could use to create the table layout instead of the row number? Or any other ideas?

Ideally, the names would be sorted first vertically, then horizontally, but I would be alright with horizontally then vertically.

Any help would be appreciated!

Solved Solved
0 3 255
1 ACCEPTED SOLUTION

Steve
Platinum 5
Platinum 5

I'm thinking you'd have to use an HTML template rather than a Docs template. See also: Part 1 - Almost pixel perfect pdf reports from automation

View solution in original post

3 REPLIES 3

Steve
Platinum 5
Platinum 5

I'm thinking you'd have to use an HTML template rather than a Docs template. See also: Part 1 - Almost pixel perfect pdf reports from automation

Using this INDEXOF() technique authored by @Steve , you can achieve a result close to what you want using a Google Doc template. If you prefer more precise formatting, I believe you need to explore a solution using an HTML template as @Steve suggested.

Template used:

TeeSee1_0-1728966713550.png

<<Start:ORDERBY(SELECT(ITEMS[id],AND(MOD(COUNT(SPLIT(ANY(SPLIT( (" , " & ORDERBY( [_ThisROw-1].[Related ITEMSs], [item_name]) & " , "), (" , " & [id] & " , ")  )  ),    " , "  )),3) = 1,[category]=[_THISROW-1].[id])),[item_name])>>
<<[item_name]>>
<<End>>

Result:

TeeSee1_1-1728966730478.png

The data used is simply a list of ITEMS which has a category reference, which I believe basically has the same structure as your data.

TeeSee1_2-1728967317431.png

 

 

Thank you!  This works for what I asked for, and you are correct that an HTML template is best for what I am actually ultimately looking for. 

Top Labels in this Space