In your "catchall" else condition "ERROR" is a string and Tableau has already established that you're going to return an integer all the time. Change "ERROR" to NULL or something else that shows an error and it will work
Thank you!!! I'll pretend I didn't ask such a stupid question. After 14 hours, I think its time to put this away.