Hi BigChris,
Your example got me trying out different case statements, and I think I finally cracked it! Here's a bit more context to explain what I did.
The table containing the author information has three fields:
- AuthorNumber (an auto-incremented ID number--e.g. 1, 2, 3)
- Author Name
- Credentials
I then created a couple of data items:
AuthCred
CASE
WHEN ([Credentials] is null) THEN ([Author Name])
WHEN ([Credentials] is missing) THEN ([Author Name])
WHEN ([Credentials] = '') THEN ([Author Name])
ELSE ([Author Name] || ', ' || [Credentials])
END
FirstAuthRecord
minimum ([AuthorNumber])
LastAuthRecord
maximum ([AuthorNumber])
Author1
CASE
WHEN ([AuthorNumber] = [FirstAuthRecord]) and ([LastAuthRecord] = [AuthorNumber])
THEN ([AuthCred])
WHEN ([AuthorNumber] = [FirstAuthRecord]) and ([LastAuthRecord] <> [AuthorNumber])
THEN ([AuthCred] || '; ')
ELSE ('')
END
Author2 (Author3, Author4, and Author5 fields follow this model, but instead of +1, they use + 2, + 3, and + 4, respectively)
CASE
WHEN ([AuthorNumber] = [FirstAuthRecord] + 1) and ([LastAuthRecord] = [AuthorNumber])
THEN ([AuthCred])
WHEN ([AuthorNumber] = [FirstAuthRecord] + 1) and ([LastAuthRecord] <> [AuthorNumber])
THEN ([AuthCred] || '; ')
ELSE ('')
END
AllAuthors
([Author1] || [Author2] || [Author3] || [Author4] || [Author5])
In addition to the issues I noted in my original post (dealing with null values and removing unneeded delimiters), I had also found myself running into problems where records had been deleted, causing the values in the AuthorNumber field to no longer begin with 1 and/or to no longer be incremented by 1. This coding appears to fix that.
So, as an example, if we originally had 5 author records for a project, and records 1 and 4 were subsequently deleted, the AllAuthors field now yields:
AuthorBBB, CPA; AuthorCCC, CPA; AuthorEEE, CPA
As a bonus, I find that the AllAuthors field exports to Excel as a single cell (instead of broken out like I had been seeing with my other attempted solutions).
This is probably much clunkier than it needs to be, but at least it's working.
Thanks again for your help!
Kristen