Is there anyway to create User Defined Functions, as opposed to use calculated fields?
No. Here's the Idea (feature request) you can vote for: http://community.tableau.com/ideas/1130
You should be able to use a variation of techniques discussed in the article below to get to where you want. This isn't the cleanest solution, but it works:
Using Stored Procedures and Functions | Tableau Software
Become a Viz Whiz on the Forums!
Support the Community and master Tableau.
Retrieving data ...