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);
let
ProfitMcode = ( Cost as number, Qty as number, Price as number) => (Price - Cost ) * Qty
in
ProfitMcode
You can then use this function in other queries - for example, adding a profit column:
let
Source = Excel.CurrentWorkbook(){[Name="tryone"]}[Content],
#"Added Profit Column using Function" = Table.AddColumn(Source, "Profit", each ProfitMcode([Cost], [Qty], [Price]), Currency.Type)
in
#"Added Profit Column using Function"
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:
let
Source = Excel.CurrentWorkbook(){[Name="tryone"]}[Content],
#"Apply Function to Source" = ProfitBySteps(Source)
in
#"Apply Function to Source"
Perhaps, to add more value to your understanding, you can describe more complex use cases for which you want to create functions?
Bookmarks