Controlling the Power BI filter context from within PowerApps

Was looking at the PowerApps Docs on how to control the Power BI Filter context from inside of PowerApps and noticed a couple of issues…Like the references to our internal MSIT servers and angle braces in the syntax…and decided a tutorial might be helpful to help people get started.

This tutorial is using the Dashboard in a day sample data that can be found here: https://aka.ms/DIAD     To make it easier i am starting with the finished version of the report

Step 1. Open the Dashboard in a Day finished report

In PowerBi.com login and select Get Data > Files and navigate to where you downloaded and extracted the Dashboard in a Day samples.  In this example i am using a workspace called “Difinity”;  as the intent is to share this PowerApps application, you would not want do this from “My Workspace”

GetFiles

getfiles2 Step 2.  Pin a visual from the Power BI report to a Dashboard

As the PowerApps Power BI control only supports visuals in Dashboards, we need to pin one of the visuals to a dashboard, in this case I am creating a new one called “PATutorial”.

PinDashboard

Step 3.  Create a Canvas based PowerApp

PA1

Step 4. Insert a Power BI Control

From the insert ribbon choose controls and scroll to the Power BI Tile

PA2

Step 5. Setup the Power BI Control

pa3

Step 6.  Add some buttons to set the filter context

On the Insert ribbon select controls and add a couple (~three) buttons.  Change their Text to that of the manufacturers in the Dash board in a day sample i.e. VanArsdel, Natura and Prium.

pa4

Step 7.  Create and set a variable to used as our filter context

In the OnSelect of each button set a variable to the manufacture name.  In this example we are hard coding the values rather than using the Button1.Text property to make it easier to include the needed single quotes around the manufacturer name.

Set(MyManufacture,”‘VanArdel'”)

pa5

Step 8. Set the TileURL property of the Power BI Control

Select the Power BI control and scroll to the TileURL property then add the section in purple below.  If your buttons don’t work there is a good chance you have added an extra space in the URL and the filter is being ignored.

 

https://app.powerbi.com/embed?dashboardId=18aaea96-cc77-45d6-bc72-19876656c513&tileId=1ff09934-db7e-458f-a670-268fc95d2d74&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6Ly9XQUJJLVVTLUVBU1QyLXJlZGlyZWN0LmFuYWx5c2lzLndpbmRvd3MubmV0In0%3d

&$filter=Manufacturer/Name eq ” & MyManufacture

pa6

Congrats you have now created a PowerApp that is hosting a Power BI Tile!

 

Some notes with this example:

If you are looking at the Power BI documentation note there are differences!

https://docs.microsoft.com/en-us/power-bi/service-url-filters

  1. myvar should start with “&” instead of “?” (because there are other URL params ahead of it)
  2. “filter” should be “$filter” (unlike in Power BI directly)

The Tile URL may look something like the following:

https://app.powerbi.com/embed?dashboardId=225c9a6a-86e9-4982-a720-5aa1132d0ff2&tileId=dc9b4418-1b31-43e6-8325-6f2d173f6507&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6Ly9XQUJJLVVTLUVBU1QyLXJlZGlyZWN0LmFuYWx5c2lzLndpbmRvd3MubmV0In0%3d” & myvar

 

and your Button OnSelect would have something like the following:

Set(myvar,”&$filter=Store/Territory eq ‘NC'”)

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s