Conditional formula based on which field is field in

I’m trying to write a formula to a field that will write someone’s name based on conditions. If {preferred name} is filled, the formulae outputs {preferred name}&" "&{last name}

otherwise, the formula output is {first name}&" "&{last name}

I can’t seem to write the if statement so it works. Any thoughts?

The formula would be: IF({preferred name},{preferred name},{first name})&' '&{last name}

The logic of the formula above is: IF {preferred name} is not empty, insert value of {preferred name}, otherwise insert value of {first name}