Guide: Multiple Audiences for Power Apps in Power BI with Calculated Measures

Guide: Multiple Audiences for Power Apps in Power BI with Calculated Measures

Introduction

This article is part of a series on integrations between Power BI and Power Apps.

Part 1 of the series showed how to get started with creating and embedding a basic Power App in a Power BI report for data write-back. Find the article here: Link to Part 1!

Part 2, taught you how to display the write-back data live in Power BI with a DirectQuery connection. Find the article here: Link to Part 2!

Part 3 of the series, goes through layouting your embedded Power Apps in Power BI. Find the article here: Link to Part 3!

In Part 4, this article, you will learn how to use one Power App in two different Power BI reports with different behaviour, and be inspired by potential use cases.



Passing Parameters to Power Apps from Power BI

In the first Parts of this article series, we have multiple times been adding Fields from our Power BI model to our Power Apps.

The process is pretty simple, with a quick overview of the process being as follows:

  1. Create a Power Apps for Power BI visualization in your Power BI report in the Power BI Service.
  2. Add your Fields to the Fields list of the visualization
  3. ‘Edit’ the visualization, to open Power Apps Studio in a new browser tab.
  4. Retrieve the data sent to Power Apps via the PowerBIIntegration.Data element.

For a more in depth guide, check out Part 1 of the series, which is linked at the top of this article.

However, in addition to passing normal data fields to your Power Apps, you may also send Calculated Measures. To do this, simply create any kind of Calculated Measure in your Power BI.?

You may create a hardcoded value to be retrieved in Power Apps:

M_AccessParameter = “Admin”        

Or you may create a dynamic parameter, which takes respect to filters being applied in your report:

M_DynamicSalesParameter = “SUM(Orders[Sales])        

To use these parameters in Power Apps, simply add the Calculated Measures to the Fields list of the Power Apps for Power BI Visualization, like you would any normal field.

Der er ingen alternativ tekst for dette billede

In Power BI, the value can be retrieved in a number of ways with the PowerBIIntegration.Data element. The important thing to know is that PowerBIIntegration.Data returns a table. Hence, you may use a formula like below, to extract a hardcoded measure:

First(PowerBIIntegration.Data).M_AccessParameter?        

Or you may use a function, to return the dynamic output from your dynamic parameter, depending on the filters applied in Power BI:

Max(PowerBIIntegration.Data, M_DynamicSalesParameter)        


Use Case Ideas for Parameterizing your Power App

Once the value from the Calculated Measure is correctly loaded in your Power App, you can use it to alter the behaviour of your Power App, depending on which Power BI Report is used to call the app.


You could...

Use a hardcoded Calculated Measure to make your App relevant to multiple audiences, by show/hiding controls in your Power App (e.g. a Control Panel for Admin Users), depending on which Power BI Report is calling the app.

Imagine two different Power BI Reports. One for Management (Report A) who needs to be able to access an Admin Panel in the Power App, and a slightly different department-specific report (Report B) with no Admin Panel access.

To solve this, in Report A, Create the Calculated Measure:

M_AccessParameter = “Admin”        

And in Report B, Create the Calculated Measure:

M_AccessParameter = “User”        

In Both reports, add the Calculated Measure to the field list of the Power Apps for Power BI Visualization.

In Power Apps Studio, add conditional logic on the Visiblity Property of one or more of your controls. E.g, change the Visiblity Property on your Control Panel button to:

If(First(PowerBIIntegration.Data).M_AccessParameter = “Admin”, 
true, false)        
Der er ingen alternativ tekst for dette billede


Or you could...

Use a dynamic Calculated Measure, to auto-complete certain values in your Power App (e.g. the default value of a dropdown), depending on dynamic calculations in Power BI, leveraging the full computing power of Power BI.

Imagine a Power BI Report that contains a DAX calculation to get Sales Amounts. The calculation is being filtered by multiple filters.

In the same report is a Power App, where users should add comments, and in a dropdown indicate the level of the Sales.

Der er ingen alternativ tekst for dette billede


To solve this, Create the Calculated Measure for your Sales amount:

M_DynamicSalesAmount = “Insert Your Own Calculation”        

Add the Calculated Measure to the field list of the Power Apps for Power BI Visualization.

In Power Apps Studio, change the default value of a dropdown control, to conditionally check the value of the Measure. E.g:

Der er ingen alternativ tekst for dette billede

And observe how the Dropdown value will now automatically change!

Also consider populating the rest of the controls’ default values, to ensure proper data quality throughout the entire input:

Der er ingen alternativ tekst for dette billede


But the use cases do not stop there…. You could also:

Use a hardcoded Calculated Measure to alter which data source you are writing data back to with your Power Apps.

Imagine two different Power BI Reports. One for Management (Report A) that displays all data, and a slightly different department-specific report (Report B) filtered via RLS to only the current user’s department.

In each report, users need to submit comments to a write-back data source, but for security reasons, the management and department-specific comments are not allowed to be stored in the same table.


To solve this, in Report A, Create the Calculated Measure:

M_DataSourceParameter = “Management”        

And in Report B, Create the Calculated Measure:

M_DataSourceParameter = “Department”        

In Both reports, add the Calculated Measure to the field list of the Power Apps for Power BI Visualization.

In Power Apps Studio, add conditional logic to your Patch Statement for submitting your Comments. E.g:

On Select:

Patch(If(First(PowerBIIntegration.Data).M_DataSourceParameter 
= “Management”, ‘dbo.ManagementComments’, ‘dbo.DepartmentComments’),
Defaults(), {Comment: ti_CommentInput.Text})        


Or you could...

Use a dynamic Calculated Measure to change the value of a dimension in your write-back data

Imagine two different Power BI Reports. One for Management (Report A) that displays all data, and a slightly different department-specific report (Report B) filtered via RLS to only the current user’s department.

In each report, users need to submit comments to a write-back data source, but in a column the name of the User’s department should be stored.


To solve this, in Report A, Create the Calculated Measure:

M_DepartmentParameter = “Management”        

And in Report B, Create the Calculated Measure:

M_DepartmentParameter = Selectedvalue(UserTable[Department])        


In Both reports, add the Calculated Measure to the field list of the Power Apps for Power BI Visualization.

In Power Apps Studio, add conditional logic to your Patch Statement for submitting the comment with Department. E.g:

On Select:

Patch(‘dbo.DepartmentComments’, Defaults(), 
{Comment: ti_CommentInput.Text, Department: 
First(PowerBIIntegration.Data).M_DepartmentParameter})        


Summary

Power BI reports can be used to send parameterized values to Power Apps, by using Calculated Measures.

You can send both hardcoded values, or dynamically calculated values which leverages the Power BI computing engine, to conditionally show/hide controls in your Apps, or make controls behave differently, depending on the Parameter value.

Robin Hartmann

Microsoft Power Platform, AI and SAP – We create intelligent processes with added value for you

2 年

Alon Ahmet this exactly what we discussed today. Thanks Jon for sharing these articles ????

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

Jon Stjernegaard V?ge的更多文章

社区洞察

其他会员也浏览了