

Storing Images in a PowerBI/Analysis Services Data Models | Gerhard Brueckl on B...
source link: https://blog.gbrueckl.at/2018/01/storing-images-powerbi-analysis-services-data-models/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Storing Images in a PowerBI/Analysis Services Data Models
As some of you probably remember, when PowerPivot was still only available in Excel and Power Query did not yet exist, it was possible to load images from a database (binary column) directly into the data model and display them in PowerView. Unfortunately, this feature did not work anymore in PowerBI Desktop and the only way to display images in a visual was to provide the URL of the image which is public accessible. The visual would then grab the image on-the-fly from the URL and render it. This of course has various drawbacks:
- The image needs to be available via a public URL (e.g. upload it first to an Azure Blob Store)
- The image cannot be displayed when you are offline
- The link may break in the future or point to a different image as initially when the model was built
There is also a feedback items about this issue which I encourage you to vote for: https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/7340150-data-model-image-binary-support-in-reports
Until today I was sure that we have to live with this limitation but then I came across this blog post from Jason Thomas aka SqlJason. He shows a workaround to store images directly in the PowerBI data model and display them in the report as if they were regular images loaded from an URL. This is pretty awesome and I have to dedicate at least 99.9% of this blog post to Jason and his solution!
However, with this blog post I would like to take Jasons’ approach a step further. He creates the Base64 string externally and hardcodes it in the model using DAX. This has some advantages (static image, no external dependency anymore, …) but also a lot of disadvantages (externally create the Base64 string, manually copy&paste the Base64 string for each image, hard to maintain, cannot dynamically add images …). For scenarios where you have a local folder with images, a set of [private] URLs pointing to images or images stored in a SQL table (as binary) which you want to load into your PowerBI data model, this whole process should be automated and ideally done within PowerBI.
Fortunately, this turns out to be quite simple! Power Query provides a native function to convert any binary to a Base64 encoded string: Binary.ToText() . The important part to point out here is to use the second parameter which allows you to set the encoding of the resulting text. It supports two values: BinaryEncoding.Base64 (default) and BinaryEncoding.Hex. Once we have the Base64 string, we simply need to prefix it with the following meta data: “data:image/jpeg;base64, “
To make it easy, I wrote to two custom PowerQuery functions which convert and URL or a binary image to the appropriate string which can be used by PowerBI:
If your images reside in a local folder, you can simply load them using the “Folder” data source. This will give you a list of all images and and their binary content as separate column. Next add a new Custom Column where you call the above function to convert the binary to a prefixed Base64 string which can then be displayed in PowerBI (or Analysis Services) as a regular image. Just make sure to also set the Data Category of the column to “Image URL”:
And that’s it, now your visual will display the image stored in the data model without having to access any external resources!
Caution: As Jason also mentions at the end of his blog post, there is an internal limitation about the size of a text column. So this may cause issues when you try to load high-resolution images! In this case, simply lower the size/quality of the images before you load them.
UPDATE May 2019: Chris Webb provides much more information and a solution(!) to this issue in his blog post: https://blog.crossjoin.co.uk/2019/05/19/storing-large-images-in-power-bi-datasets
Download: StoreImageInPbiModel.pbix
This PowerBI Desktop model contains all samples from above including the PowerQuery functions!
Like this:
Recommend
-
12
Connecting Power BI to Azure Databricks I work a lot with Azure Databricks and a topic that always comes up is reporting on top of the data that is processed with Databricks. Even though notebooks offer some great...
-
2
Using Power BI Desktop Direct Query with Parameters I frequently work on projects where we have multiple tiers on which our solution is deployed to using continuous integration / continuous deployment (CI / CD) pip...
-
15
Data Virtualization in Microsoft Power BI Data Virtualization is actually a very new topic to me as I have barely seen it implemented in the real world or at any of my customers. But it becomes more and more intere...
-
17
Azure Data Factory, dynamic JSON and Key Vault references Paul Andrews (b, t) recently blogged about
-
5
Gerhard Brueckl on BI & DataI recently built a PowerPiovt model where I had to display weeks according to ISO 8601. As I came across this frequently in the past when I developed SQL Server databases (prior to 2008) I was aware that ISO we...
-
31
Processing Azure Analysis Services with OAuth Sources (like Azure Data Lake Store) As you probably know from my last blog post, I am currently upgrading the PowerB...
-
6
Analysis Services Security: Multiple Roles in Tabular vs. Multidimensional In terms of security tabular and multidimensional models of SQL Server Analysis Services are very similar. Both use Roles to handle specifi...
-
9
碳链价值APP讯,官方消息,漏洞赏金平台Immunefi表示,白帽黑客Gerhard Wagner于2021年10月5日提交了一个严重漏洞,该漏洞影响了Polygon Plasma Bridge,该漏洞...
-
5
Brought to you by This is Gerhard’s first set of interviews from KubeCon North America 2021. William Morgan shares with us some of the finer Linkerd details, such as the underlying security theme, why native...
-
5
在BI报表的设计中,配色方案往往成为一大难题,一组切合主题、搭配合理的颜色设计往往能为我们的报表,加分不少。 今天,就介绍一个AI配色的网站,利用AI为pbi报表进行配色设计。 一:网站网址 https://aicolors.co/
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK