What is Power FX?
Power Fx is a low-code, formula-based programming language used in Microsoft Power Apps to create logic and automate processes. It is inspired by Excel formulas, making it easy to learn for users familiar with spreadsheet functions. Power Fx is declarative and functional, enabling users to manipulate data, define behaviours, and create dynamic UI elements without extensive coding.
In this blog, we’ll explore how to fetch data from Microsoft Dataverse and display it in Power Pages using Power Fx.
Scenario: Dynamically Fetching and Displaying Airline Blackout Routes
To demonstrate how to fetch data from Dataverse using Power Fx, we’ll use a real-world airline-related scenario. In this example, we’ll focus on airline blackout routes, which refer to specific flight routes that are restricted or unavailable on certain days.
Our goal is to dynamically fetch blackout routes for the current day from Dataverse and display them in Power Pages. We’ll achieve this using Power Fx by retrieving records from a Blackout Routes table in Dataverse, filtering them based on today’s date, and displaying the results on a Power Pages site. This approach ensures that users always see up-to-date information on restricted routes without requiring manual updates.
Step By Step Guide:
Open Power Pages Studio and edit your site or create a new site.

Locate or Create the Page:
1. If you have an existing page:
Go to the "Pages" section and find the page where the dynamic button will be placed.
2. If you’re creating a new page:
Click on “New Page" and name it appropriately (e.g., Booking), and choose a layout that fits your design needs.

Our goal is to dynamically fetch blackout routes for the current day from Dataverse and display them in Power Pages. To make this work, you'll need to place the Power Fx formula in a suitable spot on the page, like a list component, data table, or even a simple text area, so the blackout routes show up where users can easily see them.

Since there might be multiple routes blacked out on a particular day, displaying all of them directly on the booking page could make it look cluttered. To keep things clean and user-friendly, we'll create a separate page dedicated to showing all the active blackout dates, making it easier for users to check restricted routes without affecting the booking experience.

Inside the new page, we’ll add a default list that will display all the active blackout dates, ensuring users can easily view the restricted routes without any additional setup.

Now, click on the “Edit Code” button located at the top-right corner of the Power Pages Studio. This will open the code editor where you can modify the page’s HTML directly.

Now, let’s add a “<div>” element to separate our blackout route display from the rest of the page. We’ll style it appropriately to highlight the warning nature of the blackout, using colours and formatting that makes it stand out to users. This will help ensure that the information is easily noticeable and prevents any confusion while viewing available routes.

Inside the <div>, we’ll add our Power Fx code to retrieve blackout data dynamically. This will ensure that the blackout routes are displayed in a clearly separated section.

Check if There Are Any Active Blackout Routes

Explanation:
This part
Have already started ('Start Date' <= Today()).
Have not yet ended ('End Date' >= Today()).
Are still active (Status = 0).
filters the 'Blackout Entities' table
to find blackout routes that:
Then, CountRows() checks if there are any matching blackout routes.
If there is
at least one
matching record, we proceed to display the routes; otherwise, we show a placeholder message.
Display the Title Message for Blackout Routes

Explanation:
Displays a
bold warning message
informing users that some routes are blacked out today.
The <u> HTML tag
underlines
the text for emphasis.
<br> ensures the message appears on a new line.
Retrieve and Display Up to Two Blackout Routes

Explanation:
Filters the Blackout Entities again (same conditions as before).
FirstN(..., 2) limits the results to only the first two routes to prevent overcrowding.
Concat() is used to format the output, displaying:
"* Source Place to Destination Place due to Reason"
Each route appears on a new line (<br>) for readability.
Add a 'More' Link If There Are More Than Two Blackout Routes

Explanation:
Checks if there are more than two blackout routes using CountRows().
If more than two blackout routes exist, it adds:
" ..." (an indication that more routes exist).
A red hyperlink ("more") that takes users to the Blackout Details page where they can view all restricted routes.
If two or fewer blackout routes exist, the message ends with a period (".") for a clean display.
Handle Cases Where There Are No Blackout Routes

Explanation:
If no blackout routes are found, this placeholder message is displayed instead.
This ensures the section isn't left blank.
Finally, we’ll test our Power Fx code to ensure it functions correctly in different scenarios. This includes verifying that blackout routes are fetched accurately based on the current date and displayed in the appropriate section. We’ll check whether the message appears correctly when blackout routes exist, ensuring that only two routes are shown initially and that the "more" link appears when there are additional routes. Additionally, we’ll confirm that the placeholder message is displayed when no blackouts are active. By testing these cases, we can ensure that our implementation dynamically updates and provides users with accurate and clear blackout information in Power Pages.

Also, Test the “next” link to check whether the redirect is working correctly and a blackout list is being displayed.

Frequently Asked Questions:
1. What is Power Fx, and why are we using it in Power Pages?
Power Fx is a low-code, Excel-like formula language used in Power Apps and Power Pages for logic and data manipulation. In this scenario, we use it to dynamically fetch blackout route data from Dataverse and display it in Power Pages without needing custom code or plugins.
2. How does Power Fx retrieve blackout route data from Dataverse?
Power Fx uses the Filter() function to query the 'Blackout Entities' table in Dataverse based on conditions like start date, end date, and status. The CountRows() function helps check if there are any results, while Concat() formats the data for display.
3. Why do we limit the number of displayed blackout routes to two?
Displaying all blackout routes on the booking page could clutter the interface, making it hard for users to navigate. By limiting the output to two routes, we provide a quick summary while using a "more" link to direct users to a separate page for full details.
4. How do we ensure that Power Fx updates the blackout routes dynamically?
Since Power Fx formulas run in real-time, they automatically update whenever data in Dataverse changes. This ensures that the blackout routes displayed on Power Pages always reflect the most current restrictions without requiring manual refreshes.
5. What happens if there are no blackout routes on a given day?
If no blackout routes match the criteria, Power Fx displays a default message (e.g., "Welcome to the bookings page." or "No active blackouts today."). This ensures users don’t see an empty space and get a clear indication that no restrictions apply.