Bases: A way to sort by last name (simple suggestion!)

I would like to sort my base records by the last name of an author field. (Obviously in my case, the author field is not in last-name-first style). I understand that an official “last name” sort would be super complicated and impossible to get right, so I’m not asking for that.

I thought of a simple way to solve my problem by adding a formula field and sorting by that field. If there were formulas that did two simple things:

  • Convert string to list (split by string), plus
  • return list element (last)

If author is a text property, then this returns the last word:

author.split(" ")[-1]

You can put that formula in a Bases property then sort on it.

But the method you’re asking for doesn’t account for two-word surnames, suffixes, multiple authors, and the like. A better practice would probably be to have a surname property in the note or, as you mentioned, type the surname first.

2 Likes

I was going to suggest using a text property or the file name (but too slow in doing my local tests):

~~~base
formulas:
  surname: name.split(" ")[1]
views:
  - type: table
    name: Table
    filters:
      and:
        - name.isTruthy()
    order:
      - file.name
      - formula.surname
    sort:
      - property: formula.surname
        direction: ASC

~~~

~~~base
formulas:
  surname: file.name.split(" ")[1]
views:
  - type: table
    name: Table
    filters:
      and:
        - name.isTruthy()
    order:
      - file.name
      - formula.surname
    sort:
      - property: formula.surname
        direction: ASC

~~~

moved to help because this is possible with some forumula

1 Like

Hiya, Guapa, just want to point out that using index “1” works only on two-word names. So for, say, Zora Neale Hurston and Plato, you’d get “Neale” and null.

I know “-1” isn’t perfect either, so if you did see it—and you and I just subjectively prefer different, imperfect methods—then carry on! Commenting just in case you (or ChrisQ) hadn’t noticed the difference.

1 Like

Thanks, dawni! I looked at the help and didn’t see those functions. I guess I looked in the wrong place.

Thank you. I need to do some research to understand the difference between what 1 and -1 are doing. Only tried with name–surname pairs. I am sure your solution is the right way to go. Just need to work out why. :+1::slightly_smiling_face:

EDIT: [1] retrieves the second element; [-1] retrieves the last element. Brilliant. :star_struck:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.