Showing a field if it isn't empty else showing another field

I have a contacts table. It contains NameLast, NameFirst and NamePreferred fields. The NameFirst field always has content. The NamePreferred field sometimes has content.

I want to display the full name using the NamePreferred if it has content else using the NameFirst if the NamePreferred field is empty.

How would I achieve such a thing?

In a text display object, you could use a formula like

?(NamePreferred = "", NameFirst + " " + NameLast, NamePreferred)

The ?( function first evaluates the first parameter to see if it is true or false. If it’s true it returns the value of the second parameter, and if it’s false, it returns the value of the third parameter.

1 Like

Thank you! That solved my problem!

The ?( function mentioned by Dave is a great all-purpose function for this kind of problem. I use it all the time.

In this situation, there is also another function that could be used, the defaulttext( function.

defaulttext(NameFirst+" "+NameLast,NamePreferred)

There’s nothing wrong with using ?( for this formula, I just wanted to mention this alternative since it’s a bit simpler for this particular application.

Sorry, I actually edited the ?( so that I would always have the full name, either preferred name + last name or first name + last name.

My full expression was:
?(NamePreferred = "", NameFirst + " " + NameLast, NamePreferred + " " + NameLast)
This works

Replacing it with:
defaulttext(NameFirst + " " + NameLast, NamePreferred + " " + NameLast)
Does not work. It only gave me last names where the NamePreferred was empty.

It does not work, because the second argument is not empty this way.

Use this instead:

defaulttext(NameFirst, NamePreferred) + " " + NameLast
1 Like

I see the light! Thank you!