Hi @brucemZA :
Do you want to encapsulate a long piece of code as a custom function and then you can use this function by calling the function name?
The most direct answer is: This is an idea under review.
If you want to implement this feature, please vote for this idea:
https://powerusers.microsoft.com/t5/Power-Apps-Ideas/An-option-to-create-new-custom-functions-in-PowerApps-in/idi-p/151923
In addition, there are three alternatives:
1\Using Flow.
You can call Flow in PowerApps, and Flow can return specific results to PowerApps. In other words, you can delegate the data processing process to flow, and you only need to fill in the name of the flow and the necessary parameters for each call.
The following connection is a case I made (1\using a button in the app to trigger the flow. 2\the flow stores the picture to onedrive and then gets the sharing connection. 3\The flow returns the sharing connection to powerapps)
https://powerusers.microsoft.com/t5/Building-Power-Apps/capture-photo-and-save-image-locally/m-p/577130#M179919
I think this link will help you a lot:
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/using-logic-flows
2\Createing a custom connection.
It's not a simple process today. The main process to add a custom function is to create a custom API, where the function would be executed in the server, and in your app you'd add a connection to that API.
3\Using custom Components.I'v made a test for your reference:
Components are reusable building blocks for canvas apps so that app makers can create custom controls to use inside an app, or across apps using a component library. Components can use advanced features such as custom properties and enable complex capabilities.
In other words, you can encapsulate the data processing process into a custom Component, and then implement code reuse by using this Component.
I assume that the formula I want to customize is number1*number2.
Step1: add a compentent
In this compentent
Step2: add two cunstom proeprty(Input1/Input2)
- property type:Input
- Data type:number
Step3: add a cunstom proeprty(Output1)
- property type:output
- Data type:number
Step4: add a label control(Label1_2)
Text
Parent.Input1*Parent.Input2
Step5: set this component's Output1 property to:
Value(Label1_2.Text)

Back to my screen and add a custom component(Component1_4)
step6\Add two textinput controls(TextInput3/TextInput3_1)
step7\set the Component1_4
Input1
Value(TextInput3.Text)
Input2
Value(TextInput3_1.Text)
step7\Add a label and set it's Text preoeprty to:
Component1_4.Output1

Best Regards,
Bof