This is not possible in QuickSight, normally you can use calculated fields inside other calculated fields but no variables or functions can be defined.
At AWS, our roadmap is primarily driven by our customers. Your feedback helps us build a better service. I have tagged this as a feature request.