Forum Discussion
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.
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.
14 Replies
- koenverbeeckAdvocate II
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.
- AnonymousNot applicable
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.
- SqlJasonMemorable Member
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.gifI 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?
- AnonymousNot applicable
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)
- dvotfFrequent Visitor
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.
- Greg_DecklerCommunity Champion
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.
- AnonymousNot applicable
Hi, I tried with chiclet slicer. The image still doesn't show.
There was a visual named Image Viewer. Now no longer available.
Any suggest of dynamic image display in Power BI?
Thank you!
- khushboo_dixitFrequent Visitor
You can use "HTMLViewer" custom visual (available on Power BI store) to do the same thing as "ImageViewer" visual. The only catch being, you'll have to create html <img> tag for the images to display.
- AnonymousNot applicable
Hello,
That is not valid for calculated measures, why? It's mandatory.
I am looking for an image based on a sum of values, and the result in the table is the URL (the one I put in a conditional for the calc. measure) as a text, not as an image.
Regards