Guide: Auto-Trigger Button OnSelect Actions in Power Apps when selecting data points in Power BI

Guide: Auto-Trigger Button OnSelect Actions in Power Apps when selecting data points in Power BI

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.

Der er ingen alternativ tekst for dette billede

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.

Der er ingen alternativ tekst for dette billede


I want to extend the functionality of my report, with a Power App which accomplishes the following:

  • I want to create a LookUp Extension for my Report, where I can look up additional information about the Products belonging to the Product Categories in my report.
  • I want the app to dynamically display a Gallery of Items, based on whatever Product Category i select in Power BI.
  • I want the app to display a Loading Spinner each time i click a data point in Power BI, while my data is being loaded into the gallery, so the user knows what is going on.



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:

Der er ingen alternativ tekst for dette billede
Tip: Try using disambiguators like the ‘As’ operator to easily distinguish between columns of the same name, whenever you do LookUps in Power Apps.

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:

Der er ingen alternativ tekst for dette billede

And populating a Gallery with said Collection, allows us to display exactly the information we are looking for, inside the app:

Der er ingen alternativ tekst for dette billede


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:

Der er ingen alternativ tekst for dette billede

Displaying a Loading Spinner is now as simple as inserting one, and making its Visibility property depend on the Variable above:

Der er ingen alternativ tekst for dette billede
Tip: Try out the 'Modern Controls' preview feature in your Power Apps settings, to have a built-in loading Spinner option available!


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.

Der er ingen alternativ tekst for dette billede
Der er ingen alternativ tekst for dette billede


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!

Der er ingen alternativ tekst for dette billede

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:

Der er ingen alternativ tekst for dette billede


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:

  • Set Variables (Which can in turn be used to control visibility, placement or behaviour of the app).
  • Submit values with Patch/Collect.
  • Trigger Power Automate flows including passing data from PowerBI/Apps to the flow.
  • Or just Look Up information in other data sources, using APIs, Custom Connectors or anything else you can imagine you would do “OnSelect”.


Do you have any other cool ideas for interactions we can use this integration for? Feel free to reach out!

Christoffer Struve S?mod

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 :)

要查看或添加评论,请登录

Jon Stjernegaard V?ge的更多文章

社区洞察

其他会员也浏览了