Guide: Auto-Trigger Button OnSelect Actions in Power Apps when selecting data points in Power BI
Jon Stjernegaard V?ge
Microsoft MVP | Data Speaker, Trainer & Consultant | Founder @ Fabric Symposium
Introduction
If you have ready some of my previous articles, you know that I find Power Apps embedded in Power BI reports absolutely fascinating. You can easily write data back to your sources (Link), create LookUp extensions and generally enhance the functionality of your reports (Link).
One gripe I’ve always had however, is that all interactivity between Power BI and Power Apps hinges on one, somewhat weak, link: The PowerBIIntegration.Data object.
The object act as a regular table data source being loaded in to the app, and it being the only link between the two tools also means, that there is seemingly no way to send other commands from Power BI to Power BI (e.g, no way to trigger OnSelect actions in the Power App, when you are clicking items in Power BI).
Or is there…?
As it turns out, we can leverage the Combo Box control in Power Apps, to ‘listen’ on the incoming data from PowerBIIntegration.Data, detect changes, and trigger all kinds of actions when we detect said changes.
Let me show you how!
Initial Setup of Power BI + Use Case
First, we need to create a simple Power BI report with an embedded Power App. If you have not tried this before, check out my other guide on the subject to get started: Link to Guide.
For this guide, I have created a simple overview of Sales by Product Category.
I want to extend the functionality of my report, with a Power App which accomplishes the following:
Setting up the Power App
To accomplish this, I start out by creating a Power App from inside Power BI, as described in the guide linked above, to establish the PowerBIIntegration.Data link.
With the app ready for development, I'll first create a button in Power Apps, and alter the 'OnSelect' property to create a collection of the Products to display in the gallery:
The code above will, whenever the button is clicked, Return all Products from the Product Table that matches the selected Product Category in Power BI. Further, an additional column with the name of the Product Category is added.
A quick check of the Collection shows us the formula is running correctly:
领英推荐
And populating a Gallery with said Collection, allows us to display exactly the information we are looking for, inside the app:
Automating the Button Selection
However, if I want this to not depend on a manual button click, but happen automatically upon selecting a category in Power BI, and also show a Loading Spinner while the Collection is updating, we can make a few tweaks.
First, I alter the code to display a Loading Spinner as well, by toggling the state of a Variable before and after our ClearCollect() operation:
Displaying a Loading Spinner is now as simple as inserting one, and making its Visibility property depend on the Variable above:
Now for the automation part. As the only link between Power BI and Power Apps comes from the PowerBIIntegration.Data object, we need to somehow detect when the values in Power BI change. How can we do that? Well, some Power Apps controls have a property called "OnChange".
Text Labels do not have an OnChange property. Neither does Dropdowns. But Combo Boxes do! We can leverage this to our advantage, and setup a Combo Box to be populated with the first ProductCategory item coming in from Power BI, and firing an OnChange event whenever this happens.
First Add a new Combo Box, and populate it with the items from PowerBIIntegration.Data. Next, set the DefaultSelectedItems Property, as well as the DisplayFields.
Do a quick test run, by saving and publishing your app, and verify that the item in the combo box changes, as you select new things in Power BI.
Now comes the final and fun part: In the OnChange property of the Combo Box, simply add a function to Select the button you have already created. Now your button will trigger every time you select a new item in Power BI!
We can now hide the button and Combo Box by setting Visibility to False, rearrange our Gallery, and test the full setup in Power BI:
Use Cases & Summary
The above Use Case is just one of countless possibilities. Being able to trigger Buttons in Power Apps, by clicking data points in Power BI allows us to:
Do you have any other cool ideas for interactions we can use this integration for? Feel free to reach out!
Senior Consultant at Ascendit
1 年Clever use and great share - hadn’t considered for the Power BI connector :) And this is just the tip of the iceberg (although er very neat one!) when it comes to use-cases. I’ve also utilized combox’ for applying a JavaScript-like “auto formatting of Numbers” to automatically insert thousand separators and decimals while typing in an inputbox and triggering other OnSelect/OnChange during input :)