Power Platform
7
 minute read

Write-Backs: Fabric Data Warehouse Meets Power Apps

Cristian Prifti
28 Oct
2024

Introduction

I had the pleasure last week of presenting together with Bogdan, at the Devon and Cornwall Power BI user group, where we showcased the synergy of Power BI with Power Apps, looking from both angles. You can watch the recording here.

To make the session more challenging, we chose to base our showcases on a Fabric data warehouse rather than the usual direct query method, which typically uses Dataverse tables. This posed a challenge because of a key difference between the two data sources. Dataverse tables have a default enforced primary key (the table rows have a unique identifier defined as GUIDs), while a Fabric data warehouse does not enforce primary keys. This distinction matters because the Patch function in Power Apps can only be used, if the destination table includes a primary key.

In this case there are two possible solutions to perform the write back:

  • Creating a Power Automate flow which will execute a SQL statement - This is what we will be focusing on in this blog post.
  • Calling a SQL stored procedure from Power Apps that will execute the write back - You can catch the recording here, to see how this is done with the support of collections.

Before we go into the details, the overarching context of the showcase, was a Power BI report which has an embedded Power Apps, both leveraging data from a Fabric data warehouse.

Power Automate Flows (in the Power Apps context)

From within the Power Apps canvas, we can start the creation of a Power Automate flow, by using the left menu. Click on the more options icon and then Power Automate.

Image showcasing the Power App Canvas and how to open up the Power Automate Section
Power App Canvas -> Power Automate Section

Since we don’t want to use an existing Power Automate flow, click on 'Add Flow,' then choose 'Create New Flow,' and finally select 'Create from Blank' or browse through the available templates.

Image showcasing the creation of Power Apps associated Power Automate flow.
Power Apps associated Power Automate flow creation.

Clicking on it opens the Power Automate editing canvas within the Power Apps editing window.

Image showcasing the Power Automate embedded editing canvas inside Power Apps.
Power Automate embedded editing canvas

The flow will consist of three steps:

  • Instant Trigger - Is already added and works like a regular instant trigger, only that it gets triggered only from inside the application.
  • Execute a SQL Query - This step will run a Set statement by leveraging the dynamic inputs defined in the trigger, which will be supplied by Power Apps.
  • Respond to a Power App or Flow - This action will be doubled to have a different message if the action execution is successful or if it fails.

Instant Trigger

This step was added by default when the initial canvas was opened, however this is a vital step. In this step we will define the input parameters coming from Power Apps, that will be used when executing the SQL statement.

Three inputs are sourced from the app, while an additional input is retrieved from the app's data gallery.

  • OrderNumber - String/Text - Is already present from the data source and we will need this, as this is the unique identifier of the record that needs to be updated.
  • ServiceAgent - String/Text - Input provided by the end-user through the app.
  • ServiceDate - Date - Input provided by the end-user through the app and needs to be defined in the ISO standard (YYYY-MM-DD).
  • Status - String/Text - Coming as input from the apps as a predefined value.

For each field, I have included the corresponding data type, as this is very important. Selecting an incorrect data type will cause the SQL statement execution to fail.

When adding a new input parameter, first select the data type, then provide a name and optionally a description of the input.

Image showcasing the trigger details and input parameters creation
Trigger Details - Input Parameters Creation

NOTE
If an input parameter needs to be deleted, but is used in a subsequent step, you need to remove the respective usage reference from the other steps before you can delete the parameter from the trigger.

Execute SQL Query

To write data to a Fabric data warehouse, you’ll need both the SQL connection string and the table name. We will then write the SQL statement and introduce the dynamic content provided through the trigger.

Image showcasing the Power Automate SQL execution action with dynamic content
Power Automate SQL execution action with dynamic content

This is how the code looks:

UPDATE ActualWonders

SET 
ServiceDate = 'InputValue1', 
ServiceAgent = 'InputValue2', 
Status ='InputValue3'

WHERE 
OrderNumber = 'InputValue4'


Respond to a Power App or Flow

The final action sends feedback to PowerApps, indicating whether the action executed successfully or if it failed. This is done by adding the same action twice as parallel steps, with one action defined to run if the SQL execution is successful and the other action to run only if the SQL execution fails or got timed out. This configuration is managed by adjusting the Configure Run After settings under the options menu (three dots) for each action. You can also see below that the direction arrow looks different for the second action, which will run only if the execution fails.

Image showcasing the Power Apps response action based on previous action outcome
Power Apps response action based on previous action execution outcome

Running the Power Automate Flow

Creating the flow will add it into the Power Apps context menu. The next step is to invoke the flow in the Power Fx formula, corresponding to the Assign Order button’s OnSelect property. The important thing to remember is that, when we invoke the flow, the order of the input parameters defined in Power Automate matters, however you will get IntelliSense support for the parameters. The invoke syntax defines the function as 'FlowName'.Run().

Image showcasing the Power Automate flow incorporation inside the PowerFx formula.
Power Automate - Power FX Invoke Step

Bonus - Flow Wait Time Solution

The Power Automate flow will execute within a few seconds, but due to the Direct Lake connection, you will need to consider a delay of at least 20-25 seconds (recommendation is to consider 30 seconds) until the data is visible in Power BI. To signal the waiting time to users, we can use an SVG or the built-in modern Spinner control.

NOTE
In order to try this out, you need to first allow the new modern controls features from Settings ➡️ Updates ➡️ Moden controls and themes

As we look at it for a longer time, to make it more engaging for the users, we will use 4 spinners, each providing a different message.

Image showcasing the Power Apps Spinner Modern Control
Power Apps Spinner Modern Control

For each spinner added, we will open up the Visible property and define a variable which will be used later to display/hide the spinner. Afterwards we will define the text to be displayed, but also the spinner size.

Image showcasing the Power Apps definition of variables for properties
Power Apps definition of variables for properties

In addition, you see that all spinners are positioned within a container, so that we can also use a variable to create a blur effect.

Image showcasing the important spinners container visibility property
Important spinners container visibility property

After they are added, we will go back to the Power Fx formula captured in the OnSelect property of the Assign Order button. The formula will use a timer and play with the visibility of each spinner through those defined variables.

Image showcasing the Power Fx formula sample for one spinner
Power Fx formula sample for one spinner

Now let's look at the full output:


With this integration, Power Apps and Power BI work together to streamline data management, bringing near real-time insights and updates directly to your analytics environment. Whether you're using the Fabric data warehouse for scalability or seeking responsive Power BI visuals, these steps help you make the most of your setup. Ready to take your Power Platform skills further? Start implementing, and watch your data flows transform!