Remove duplicate tags if values are equal

Hi experts,
many of my files have multiple tags with the same value. For example two YEAR tags with the same value of 2009.
I've tried to remove those duplicate tags with the quick action, but it removes all duplicate tags, independently of the value. So I would lost information.

Is it possible to remove duplicate tags only when the values are equal?

Try
"$if($eql($meta(year,0),$meta(year,1)),1,0)" IS "1"
Select the files,
Delete the superfluous YEAR field with the extended tags dialogue.

It works!

Many thanks

Sorry to drag this back up, but after I used your super helpful filter code, I don't see duplicate ALBUMARTIST fields when I open extended tags for multiple files from different artists - just one.
nodup

If I delete it then both get deleted. Should I be approaching this a different way? I've tried a Merge action script, but it's not working either:
aa

I'll be honest, I don't know the origins of this script as it's been on my mp3tag installation for years now and I'm only coming back to mp3tag after updating.

I do not see a merge script in the dump - it is a split action.
I would really use thee action Merge duplicate fields and use e.g. == as field separator.
Then use an action of the type "Replace with regular expression" for e.g. ALBUMARTIST
Search string: (.*)==.*
Replace string: $1
All this in the filtered list

What exactly does your filter look like?

"$if($and(NOT %albumartist% IS '', $if($eql($meta(albumartist,0),$meta(albumartist,1)),1,0) IS 1),1,0)" IS "1"

The filter works fine, it's just the originally suggested method of fixing them doesn't work when trying to batch remove the duplicates.

Thanks for the help! Worked like a charm.