Microsoft Fabric Write-Back Revisited: Maintaining RLS tables with Power Apps & Stored Procedures

Introduction

Recently I posted my guide on Data Write-Back to Fabric Data Warehouse with Power BI and Power Apps: Live Data Write-Back to Fabric Data Warehouse from Power BI w. Power Apps and Power Automate – Downhill Data (downhill-data.com)

That solution uses Power Automate to circumvent the traditional Power Apps x Fabric problem, of Fabric Warehouses not supporting enforved Primary Keys, which is otherwise required for Power Apps write destinations.

However, a good friend of mine, Chris Hansen aka Skills Thrills asked me: Why don’t you just use Stored Procedures? I had no good answer, and hence, here is a quick guide on accomplishing Write-Back to Fabric Data Warehouse from Power Apps, using Stored Procedures.

The Case: Adding new users to Row Level Security (RLS) table in Fabric Data Warehouse

I have created a Fabric Data Warehouse using the famous Taxi Trip dataset. This dataset, I wish to use in Power BI reports, but I want to restrict access to data with Row Level Security (for a guide on how to configure DirectLake semantic models for Row Level Security, see my guide here: How to setup RLS in Microsoft Fabric / Power BI without breaking DirectLake functionality – Downhill Data (downhill-data.com)). Hence, to control RLS, I have a UserTable as well.

To understand the model, here is a glimpse of the Geography table of my model, as well as the User Table, which should allow a logged in user to see one or more States from the Geography table:

Now, what I would like, is to be able to add new rows of data to the UserTable, without having to write SQL Queries in my Fabric Data Warehouse. Rather, I would like to be able to user simple inputs in a Power App, to add this data.

To do this, we can create a reusable Stored Procedure, as well as a Power App to call said SPROC.

Creating the Stored Procedure

Let’s create the Stored Procedure first.

Create a new SQL query from blank, or use the SPROC template:

In this case, we wish to pass two parameters to the procedure, ‘State’ and ‘UserEmail’, and insert those value pairs into the User Table. Hence, we can modify the SPROC accordingly:

Don’t forget to run this query, as be need to create and persist the SPROC in our Fabric Data Warehouse. After running, the procedure will be available under the corresponding folder in the Warehouse:

Creating the Power App to call the SPROC

Next, we need a Power App to call this SPROC and feed it with the values we wish to insert. I will not go through this process A-Z, but suggest you to get inspired by one of the many guides available out there: Guide: Adding Write Back capabilities to your Power BI reports with Power Apps – Part 1: Getting Started – Downhill Data (downhill-data.com)

For this example, I am building an app that looks like the following, and which can be used either as a standalone app, or embedded inside a Power BI report (or even inside a Power Point, if you are crazy enough: Let Power Point users write data directly to your database w. Power BI & Power Apps – Downhill Data (downhill-data.com)

For this app, I have simply created a Dropdown to choose between States, a Text Input for inputting user emails, and a button to trigger the Stored Procedure.

To make the app work, we further need to add a Data Connection to the Fabric Data Warehouse. To do this, first find the SQL Connection String in your Fabric Warehouse settings:

Then create a new SQL Connection in your app:

And input your copied Connection String as well as the actual name of the Warehouse as the database name:

For this app I will connect to my Geography table, which I’ll use as a Read-Only table to populate my dropdown of States:

And then under the Stored Procedures tab, I’ll select the newly created SPROC:

To run the SPROC, all I need to do, is to add the line of code below, which assigns the User Inputted variables to the SPROC and runs it:

Demo_TaxiWarehouse.dboAddRLSUser({state: ddState.Selected.Value, usermail: tipEmail.Text});

Now, If I fill out the inputs, and click the button, new rows will be added to my RLS table:

And that is actually all there is to it! You now know how to perform Write-Back to your Fabric Warehouse using Power Apps and Stored Procedures.

Advanced Implementations

There are many ways to build on this functionality.

Write Back embedded in Power BI

This app, as well as any other Power App, may be embedded inside Power BI. This allows for front end users to effectively manipulate data in your Fabric Warehouse.

You may allow them to write comments, input budget values, maintain master data and much more from within an interface they easily understand, but which is fully under your control. This functionality may even be embedded inside Power Point!

Bulk Record CRUD operations from Power Apps

You may also choose to Create, Update or Delete records in Bulk from your Fabric Warehouse w. Power Apps. Either loop through a list of records in your App, executing the SPROC once for each record, or even better, pass a table of records as a JSON Object to your SPROC, and handle the parsing and CRUD operations in the SPROC itself.

Your Idea here?

Perhaps you have another idea for building on top of the outlined Write-Back with Stored Procedure functionality? Please let me know – I am curious to hear…

Also check out these other blogs:

Bulk Write-Back w. Translytical Task Flows in Microsoft Fabric / Power BI: Writing a single value back to multiple records at the same time

Introduction On this blog we’ve previously covered quite a few areas of Translytical Task Flows: Having presented a few sessions on Translytical Task Flows at conferences in the past moths, there is one major recurring question: How do you write-back multiple records at once? If you ask me, the questions of bulk write-back/writing back multiple…

Fabric Quick Tips – Pushing transformation upstream with Self Service Views and Tables in Visual Queries for Lakehouses/Warehouses/SQL DB

Introduction Recently, I’ve experienced a huge influx in requests from Microsoft Fabric customers wanting a good way for user’s to push data transformation upstream, following Roche’s Maxim: Data should be transformed as far upstream as possible, and as far downstream as necessary. To elaborate slightly, there are tons of Power BI Semantic Models out there…

Organizing your Microsoft Fabric Data Platform: Tags and Task Flows

Introduction We’ve arrived at the final level of detail in our series on Organizing your Microsoft Fabric Data Platform. So far we’ve covered, from broadest to narrowest scope: This time we go all the way down to the Item level on our platform, and describe strategies for labeling and categorising individual items by using Tags…

Something went wrong. Please refresh the page and/or try again.

2 responses to “Microsoft Fabric Write-Back Revisited: Maintaining RLS tables with Power Apps & Stored Procedures”

  1. […] Microsoft Fabric Write-Back Revisited: Maintaining RLS tables with Power Apps & Stored Procedure… […]

    Like

  2. […] Maintaining RLS Tables in Fabric from Power Apps: Microsoft Fabric Write-Back Revisited: Maintaining RLS tables with Power Apps & Stored Procedure… […]

    Like

Leave a comment