This expression looks like it is working correctly for me:
if(!isempty([artist]), [artist] - [album artist], - [album artist])
That says:
- If [Artist] is filled (not empty) then output: [Artist] - [Album Artist].
- If [Artist] is empty, output: - [Album Artist]
That seems to be working perfectly well on my files. However, that's not the way I'd do it. You're making it much more complex than is needed. Your desired output is
almost equivalent to this:
[Artist] - [Album Artist]
That will do
basically the same thing. When any field value is empty, it is omitted in the output of the expression, so [Artist] will be empty when it is empty. The problem with that is
only the space before the dash, which will always output (whether [Artist] is empty or not). So the problem is that when [Artist] is empty, you'll get a leading blank space before the dash. So, a simple way to fix that would be to use
FixSpacing():
FixSpacing([Artist] - [Album Artist])
Or, if you only want to show the space-dash-space when [Artist] is filled, then use
Delimit():
Delimit([Artist], / -/ )[Album Artist]
And, finally, if you never want to see the space-dash-space unless
both [Artist] and [Album Artist] are filled, then:
If(IsEmpty([Album Artist]),[Artist],Delimit([Artist], / -/ )[Album Artist])
But really, if that's what you want, you don't need any fancy Delimit() expressions. You could just use
Clean() to remove the extraneous spaces and dashes:
Clean([Artist] - [Album Artist])
I'm not sure what you're going for, but all of these work right:
EDIT: In my screenshot above I forgot to escape the space after the dash in the Delimit() examples originally, so they have no space before [Album Artist]. I fixed the example code above, but didn't re-do the screenshot because I'm lazy.