Calculating Sales Tax
Let's say you have a list of prices and you need to calculate the sales tax for each price. The sales tax rate is 8%
. You can create a custom function to perform this calculation using Function.From
:
SalesTax = Function.From(type function (number) as number, each _ * 0.08)
Then, you can apply this SalesTax
function to a list of prices:
Prices = {10, 20, 30, 40, 50};
SalesTaxList = List.Transform(Prices, SalesTax)
The SalesTaxList
will contain the sales tax amount for each price in the Prices
list. Sales tax is 8 percent . You can then define the function type as a math function . The function as function would be multiplying by point zero eight to get that eight percent .
Converting Text to Uppercase
Suppose you have a column of text values that you need to convert to uppercase. You can create a custom function using Function.From
:
ToUppercase = Function.From(type function (text) as text, Text.Upper)
Then, you can apply this ToUppercase
function to a column of text values:
Table.TransformColumns(Source, {
{"Column1", ToUppercase}}
)
This will convert all text values in "Column1" to uppercase.
Performing Conditional Calculations
Consider a Scenario where you need to apply different calculations based on certain conditions. For example, if a value is greater than 100, you multiply it by 0.9; otherwise, you multiply it by 1.1. You can create a custom function using Function.From
:
ConditionalCalculation = Function.From(type function (number) as number, each if _ > 100 then _ * 0.9 else _ * 1.1)
Then, you can apply this ConditionalCalculation
function to a list of numbers:
Numbers = {50, 150, 75, 200};
CalculatedList = List.Transform(Numbers, ConditionalCalculation)
The CalculatedList
will contain the results of the conditional calculation for each number in the Numbers
list.