PowerBI Embedding – AppOwnsData

There are two main scenarios for embedding Power BI content:

Watch this: https://www.youtube.com/watch?v=5OF0s2t0N3w



If you need to see how it works in single page web application, please scroll down to the end of this article.

Read this article first:

The script in above article can be downloaded from here:


1. Update the parameters, then execute the script.
2. Ensure step 4 in that article: new AzureADGroup should be in “Developer settings” -> “Allow service principals to use Power BI APIs”

3. Verify Service Principal (application name) in Group Members

4. Verify AzureADGroup and Service Principal are having Admin permission in Power BI workspace


For testing an embedded app: Clone the Power BI Developer Sample at https://github.com/Microsoft/PowerBI-Developer-Samples. Open the App Owns Data solution in Visual Studio. Edit the following sections of the Web.config file. Include your Application ID (for your service principal), workspace ID and report ID.

5. Go to the solution in Visual Studio, ensure $key in step 2 is using as “applicationSecret” in web.config (we can also use the key generated in App Registration -> Certificates & secrets)

6. Optional: Go to Azure portal, grant permission in Enterprise Application and App Registered if needed

Single Page Web application for Power BI Embed

1. Clone the source at: https://github.com/CriticalPathTraining/PowerBiEmbedded

2. Go to “Demos\PowerBiDaySPA” and open it using Visual Studio Code

3. Open “AppSettings.ts” and modify value


4. Run npm install if needed

5. npm run start to try the embed in single page application

Background for Power BI Chiclet Slicer

Let’s say that you want to color your slicer to become something like this:


First, you need to create a color table for it:

TestColours =
ROW ( “Index”, “1”,”RiskType”, “Low”, “ImgURL”, “https://htmlcolors.com/color-image/85e38d.png”, “ImgAsString”, “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0AQMAAADxGE3JAAAABlBMVEUAAACF442kwz8WAAAAeklEQVR4nO3LMQ0AAAgDsPlXiwMmgo+0f7MnE9/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/33/wCFkN6z5EHC68AAAAASUVORK5CYII=” ),
ROW ( “Index”, “2”,”RiskType”, “Medium”, “ImgURL”, “https://htmlcolors.com/color-image/fdf542.png”, “ImgAsString”, “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0AQMAAADxGE3JAAAABlBMVEUAAAD99ULpYmwIAAAAeklEQVR4nO3LMQ0AAAgDsPlXiwMmgo+0f7MnE9/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/33/wCFkN6z5EHC68AAAAASUVORK5CYII=” ),
ROW ( “Index”, “3”,”RiskType”, “High”, “ImgURL”, “https://htmlcolors.com/color-image/ff9005.png”, “ImgAsString”, “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0AQMAAADxGE3JAAAABlBMVEUAAAD/kAUa1PO3AAAAeklEQVR4nO3LMQ0AAAgDsPlXiwMmgo+0f7MnE9/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/33/wCFkN6z5EHC68AAAAASUVORK5CYII=” ),
ROW ( “Index”, “4”,”RiskType”, “Critical”, “ImgURL”, “https://htmlcolors.com/color-image/ff0000.png”, “ImgAsString”, “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0AQMAAADxGE3JAAAABlBMVEUAAAD/AAAb/40iAAAAeklEQVR4nO3LMQ0AAAgDsPlXiwMmgo+0f7MnE9/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/3fd/33/wCFkN6z5EHC68AAAAASUVORK5CYII=” )


in that table:

Index: Index of the color
RiskType: The meaning of color name in this case
ImgURL: https://htmlcolors.com/color-image/hex-color.png (hex-color can be the value of the color in hex format)
ImgAsString: Use https://www.base64-image.de/ to convert the color fron ImgUrl to string, this can help improve performance when use color as background.

Then, In ChicletSlicer visualization:




Risk matrix in power bi

There are a lot of questions in community for how to build a risk matrix in Power BI. I’ve seen some of them and realize that I can do it in another way. Here is how I solve it in my report:

1. Definition of Risk Matrix

My risk matrix is defined by 2 axes: Propability (Y) and Consequense (X), the graph I want to build is similar this:


2. Number in cells

The number in each cell is the count of risk, based on the risk title. Formula for this measure column is like this:

StrRiskCount = if(DISTINCTCOUNT(AllRisks[Title]) = BLANK(), “”, “”&DISTINCTCOUNT(AllRisks[Title]))
Humm, you can see on the image above, the numbers are difference in each cell, how can we do that? Yes, we need to know the position of the cell first. I defined the position like this:
This is how we can specify the row in the specific cell: Example for the cell 1-5
To check the value in each cell, we can use the “Card” in visualization, for example with the cell 1-5 above, we can do like this:
3. Color for the cells
Depended on the location of  the risk, we can divide the risk to 4 risktypes: Low, Medium, High, Critical. Each type will associate to a specific color:
Low #85e38d
Medium #fdf542
High #ff9005
Critical #ff0000
If you need the ImageURL to the color, here is the very good link: https://htmlcolors.com/color-image/hex-color.png, replace hex-color with the value of hex-color to see the real image
If you want to get the image url for the low level above, here is the URL: https://htmlcolors.com/color-image/85e38d.png
Put cells to level, here is the example for low level:
The type for the risk:
Setup color-background for the cell:
MinRiskType = if(MIN(AllRisks[RiskTypeNo]) = BLANK(), 0, MIN(AllRisks[RiskTypeNo]))
Adjust the card visualization to make it like a square, then clone it to 24 more instances. Make sure you modify the filters in all cards to display the correct number.
Then, align them like a big square (contain 25 smaller cards)
Same as other MS tools, you can use “Format painter” to copy the format from 1 card to another card.