Reply
Frequent Visitor
Posts: 9
Registered: ‎07-06-2016
Accepted Solution

Dynamic Image Display

Hi guys,

 

I'm trying to find a way to dynamically display an image based on the values selected in a Slicer. For example, I might have a dataset that could be {Good, Medium, Bad} and I want to display either a Green, Orange or Red traffic light, depending on the worst case of what's selected. So the user would use the Slicer to select the data they want to see, and the image would change to reflect the worst case of this.

 

A simple example of the kind of table I'm looking at is:

 

Category | Severity | IconURL
     a        |       1      | http://bad.png
     a        |       2      | http://medium.png
     a        |       1      | http://bad.png
     a        |       3      | http://good.png
     b        |       3      | http://good.png
     b        |       2      | http://medium.png
     b        |       2      | http://medium.png
c | 3 | http://good.png

If the user picks Category A, I want to see 'bad.png', picking Category B gives 'medium.png' and Category C gives 'good.png'.

 

I've gotten somewhere using the ImgViewerVisual visualization, but I haven't been able to get it working properly. I can get the correct URL using a Measure but I can't set the Data Category to "Image URL" so it only displays as text. I've also tried creating a Custom Column that consists only of the URL with the worst (Min) Severity, but that does not respond to Slicer choices (no picking between Category A,B or C). I could do the the Min(Severity) on a by-category basis, but that will only work if the user is restricted to only picking one category at a time.

 

Has anyone any ideas on how to do this? I feel like it should be possible but I'm missing something.


Accepted Solutions
Super Contributor
Posts: 4,066
Registered: ‎07-11-2015

Re: Dynamic Image Display

You could probably do something along the lines of create a measure like:

 

Lowest = CALCULATE(MIN([Severity]),ALLEXCEPT(Table,Table[Category]))

 

Then create another measure like:

 

IsLowest = IF(SUM([Severity])=[Lowest],1,0)

 

Then drop your IsLowest as a filter on your table visualization of the error code images.

 

The idea here is that Lowest calculates to the MIN taking into account the Category. The IsLowest will be filtered by the row context of the table so only the lowest will be 1.

View solution in original post


All Replies
Super Contributor
Posts: 2,357
Registered: ‎06-25-2015

Re: Dynamic Image Display

@dvotf Click on the column that has the image url. In the Header ribbon in the Properties section -> Select "Data Category" - > "Image URL" (second from the bottom)

image.png

Frequent Visitor
Posts: 9
Registered: ‎07-06-2016

Re: Dynamic Image Display

Thanks for the quick reply.

 

Yes I've done that and can display the icons as images in tables or some other visualisations, but I want to be able to only show image associated with the lowest severity (and only the lowest), at a given Slicer level.

Super Contributor
Posts: 4,066
Registered: ‎07-11-2015

Re: Dynamic Image Display

You could probably do something along the lines of create a measure like:

 

Lowest = CALCULATE(MIN([Severity]),ALLEXCEPT(Table,Table[Category]))

 

Then create another measure like:

 

IsLowest = IF(SUM([Severity])=[Lowest],1,0)

 

Then drop your IsLowest as a filter on your table visualization of the error code images.

 

The idea here is that Lowest calculates to the MIN taking into account the Category. The IsLowest will be filtered by the row context of the table so only the lowest will be 1.

Frequent Visitor
Posts: 9
Registered: ‎07-06-2016

Re: Dynamic Image Display

[ Edited ]

This does the job. Nice thinking around the issue.

 

I was hoping not to use a Table to do the visualisation but it'll work.

 

Small Edit:

 

Am I right that

IsLowest = IF(SUM([Severity])=[Lowest],1,0)

Should read

IsLowest = IF(MIN([Severity])=[Lowest],1,0)

as I want to look for the Minimum value in [Severity] for my comparison?

Super Contributor
Posts: 4,066
Registered: ‎07-11-2015

Re: Dynamic Image Display

Yep, good catch!

Regular Visitor
Posts: 18
Registered: ‎11-26-2015

Re: Dynamic Image Display

Hi,

I stumbled across this post looking for a solution to display images based on a text measure. The proposed solution didn't work for me because I needed a truly dynamic solution (whereas this one was hardcoded on category).

I ended up with creating a work around using R scripts, which I detailed in the following blog post:

 

Dynamically Changing Shapes in Power BI

 

I'm not 100% happy with it, because of the dependancy on R. I hope the Power BI team implements more customization options and flexibility for images and shapes, just like in SSRS.

Super Contributor
Posts: 2,357
Registered: ‎06-25-2015

Re: Dynamic Image Display

@koenverbeeck Nice solution Koen. I'm farely certain I've implemented a flavor of this in the past using the images directly tied to the data set. I don't recall if I used Dynamic Segmentation, but the result is such that depending on the values a different image could be displayed in a card or table. Your solution has a lot more flexibility with the image itself not being constrained by the PBI visual type. Very cool, thanks for sharing.

Member
Posts: 94
Registered: ‎06-25-2015

Re: Dynamic Image Display

I think I am missing something here. Can't we just make a measure that returns the correct imageurl based on the condition, and then use it as a visual filter? Eg – http://sqljason.com/2016/04/hex-tile-grid-maps-for-power-bi.html (check out the portion where the images of the president change).

 

We can create a disconnected table in the Model (just 2 rows with ThumbsUp and ThumbsDown image url and description). Then create a measure which will return 1 for ThumbsUp if the condition is true, 1 for ThumbsDown if it’s condition is true, else 0
Test = SUMX(VALUES(Img[State]), SWITCH(Img[State], “ThumbsUp”, IF(CALCULATE(SUM(Table1[Measure]))>95,1,0), IF(CALCULATE(SUM(Table1[Measure]))>95,0,1)))

 

Now you can just add this measure to the visual filter of the ImageViewer and see that the image changes based on what you select. You can see the result below –
https://jasonsql.files.wordpress.com/2017/02/temp.gif

 

I am trying to undertsand the benefits of the R solution, and I am sure I am missing something. Is the benefit that we don't have to load the ImageURLs/images in Power BI? 

Regular Visitor
Posts: 18
Registered: ‎11-26-2015

Re: Dynamic Image Display

Hi Jason,

 

(thanks for your comment on my blog btw).

I couldn't figure out how to pass the filter to the Image Viewer, so that's why I came up with the R solution.

 

The advantage of the R solution is indeed that you don't have to download the images. The R solution will still work when disconnected.

That being said, I do prefer your solution over mine if there is an Internet connection, as it doesn't rely on an R distribution being present.