There's no "one size fits all", here - you can create custom functions in pretty much any way you choose, to serve your purpose. Your two functions can achieve the same output, but one performs a calculation when presented with number, the other performs a table transformation.
If you want to add a column to a table using a custom function, then your "ProfitMCode" function is about right (although I would recommend strongly typing your inputs);
You can then use this function in other queries - for example, adding a profit column:
Your "ProfitBySteps" function doesn't really offer any value over simply adding the Add Column step to your 'test' query - unless you wanted to repeat that table function to multiple tables. You can invoke that by passing the entire table:
Perhaps, to add more value to your understanding, you can describe more complex use cases for which you want to create functions?
Bookmarks