Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Image Binary Data to Image

Hello,

 

I have a table in SQL Server which has Image binary data in the below format - 

 

 

0x1F8C0200B28C010064
0x1F8C0200DE720100CC
0x1F8C0200DE720100CC
0x1F8C0200B28C010064
0x1F8C0200B28C010064
0x1F8C0200B28C010064

 

This is just part of the hex string. I am converting this into image URL using below function - 

 

let
    BinaryToPbiImage = (BinaryContent as binary) as text=>
let
    Base64 = "data:image/jpeg;base64," & Binary.ToText(BinaryContent, BinaryEncoding.Base64)
in
    Base64 
in
    BinaryToPbiImage

 

 

Now whats happening is the image is not being displayed. Is there some change that I need to do in my code.

 

Any suggestion would be helpful.

  • Hi Anonymous ,

     

    Please check if the method in this blog could help you.


     

    Step 7

    Change the data type of ImageData (Binary) column to text from the top panel's Transform tab.

     

    Step 8

    Go to "Add Column" and click on "Custom Column". It will open a window. Enter the column name and formula given below and click OK.

    “data&colon;image/<image_format>;base64,”&[ImageData<binary_column_name>]

     

    Step 9

    On Data tab, select Image column and change its data category to Image URL.

     


     

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

12 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello there. 

      I was following the instructions on the presented link for the image import: https://powerbipoint.com/2024/02/05/how-to-embedding-base64-images-in-power-bi/

       

      Now I've reached the last step which is "Creating a DAX measure to group chunks of the same image"

       

      When I follow the instructions my measure fails and says:

      Could you please help me with this situation.

       

      I'm trying to import images from Sharepoint so I can later upload PoweBI dashboard to Junction.

       

      Thank you in advance

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    AlexisOlson I am referring to the same article. But its not converting.

    Yes, I have set it as an Image URL. Also, does the source field needs to be binary format or text? This is what I see.

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Yes, I do have it in binary. SQL Data column type is Image if that helps

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      Hmm. Is the binary a JPEG encoding? I'm just shooting in the dark.

  • Anonymous's avatar
    Anonymous
    Not applicable

    I am not sure. The original image is either in jpeg or png

  • Please double-check that you are actually using a colon ":" rather than "&colon;" in your function.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Yes I am using colon. When I am copying the code here its automatically converting into it "&colon;"

  • Anonymous's avatar
    Anonymous
    Not applicable

    AlexisOlson There is something I noticed, when I am using the function and encoding into base64 I am getting something like this
    H4wCAMU6AADNuWVQHEDXJjpA8ABJCO7ungGCBncL7u7ubiFY

     

    Whereas if I use the same image and convert the image itself to base 64  the value is - 

    iVBORw0KGgoAAAANSUhEUgAAAV0AAAEOCAIAAACl8FO5AA

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

     

    Please check if the method in this blog could help you.


     

    Step 7

    Change the data type of ImageData (Binary) column to text from the top panel's Transform tab.

     

    Step 8

    Go to "Add Column" and click on "Custom Column". It will open a window. Enter the column name and formula given below and click OK.

    “data&colon;image/<image_format>;base64,”&[ImageData<binary_column_name>]

     

    Step 9

    On Data tab, select Image column and change its data category to Image URL.

     


     

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MmmVvv_23's avatar
    MmmVvv_23
    Frequent Visitor

    I didnt notice any special difference between:

    let 
        BinaryToPbiImage = (BinaryContent as binary) as text=>
    let
        Base64 = "data&colon;image/jpeg;base64, " & Binary.ToText(BinaryContent,BinaryEncoding.Base64)
    in
        Base64
    in
        BinaryToPbiImage

     

    and:

    "data&colon;image/jpeg;base64,"&[Content]


    In my table or SimpleImage viz looks all the same.