Host

Host

How to Use the Power Fx Host Function in Power Apps

What is the Power Fx Host Function?

The Power Fx Host Function is a formula language that is used in Power Apps and other Microsoft products such as Power Automate and Power BI. It is based on the Excel formula language and is designed to be easy to read and write. The Power Fx Host Function allows you to create complex formulas that can perform calculations, manipulate data, and control the behavior of your app.

How to Use the Power Fx Host Function

To use the Power Fx Host Function in Power Apps, you will need to follow these steps:

Step 1: Create a New Formula

To create a new formula, you will need to open the formula bar in Power Apps. This can be done by clicking on the fx icon in the top left corner of the screen. Once the formula bar is open, you can start typing your formula.

Step 2: Use the Host Function Keyword

To use the Power Fx Host Function, you will need to use the Host function keyword. This keyword is used to create a new formula that can be used across multiple screens and controls in your app. The Host function keyword is followed by a unique name for your formula.

Step 3: Add Parameters to Your Formula

Once you have created your formula using the Host function keyword, you can add parameters to your formula. Parameters are placeholders for values that will be passed into your formula when it is used in your app. You can add as many parameters as you need to your formula.

Step 4: Use Your Formula in Your App

Once you have created your formula using the Power Fx Host Function, you can use it in your app. To use your formula, you will need to reference it in your controls and screens. You can do this by typing the name of your formula into the formula bar of your control or screen.

Examples of Using the Power Fx Host Function

Here are some examples of how you can use the Power Fx Host Function in Power Apps:

Example 1: Calculating Sales Tax

Suppose you have an app that calculates sales tax for a product based on the state where it is sold. You can use the Power Fx Host Function to create a formula that calculates the sales tax based on the state. Here is an example of the formula:


Host.SalesTax(State)


In this formula, “State” is a parameter that represents the state where the product is sold. You can use this formula in your app by referencing it in your controls or screens.

Example 2: Formatting Dates

Suppose you have an app that displays a date in different formats based on user preferences. You can use the Power Fx Host Function to create a formula that formats the date based on the user’s preference. Here is an example of the formula:


Host.FormatDate(Date, Format)


In this formula, “Date” is a parameter that represents the date to be formatted, and “Format” is a parameter that represents the format to be used. You can use this formula in your app by referencing it in your controls or screens.

The Power Fx Host Function is a powerful tool for creating reusable formulas that can be used across multiple screens and controls in your Power Apps. By following the steps outlined in this article, you can start using the Power Fx Host Function in your app today.

Power Apps Training Courses by G Com Solutions (0800 998 9248)