Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ErolOld
New Member

Dax Code to adjust the transparency slider on Blank Button.

Hello,

 

I am trying to find some way to change the transparency of images based on certain values. However, this is not really possible as far as I know. If you add an image to a dashboard visual, you can only change the transparency of the color of the background of the image, if you choose to enable a background for that picture.

 

BUT.... there is a way to change the transparency of an image by adding the image through a Blank Button. If you add a Blank Button, and you enable "Fill" under Style, for that button, you can browse and add an image to that button. And within that function, "Fill", there is a transparency slider - and this slider DOES change the transparency of the entire button including the image within it.

 

What I am trying to find out is if there is a code/command that I can use to manipulate that very slider. Again, I'm aware of how to change the transparency of a color, by adding "00" to the color hex code. But this slider is not just affecting a color, but an actual image. And I need to find out how I can control that slider in a measure.

 

Here are some images for better understanding...

Blank ButtonBlank ButtonStyle - FillStyle - FillAdded imageAdded imageTransparency sliderTransparency slider

 

3 REPLIES 3
ErolOld
New Member

Hi Owen,

 

thanks for your help. Unfortunately, your first suggestion will not do the exact trick I need. I would need the image to turn 100% transparent based on certain values, to reveal another image that will be layered underneath it. That would be the ideal way. I have already considered your solution, which I will be force to go with. In that case I won't be able to layer multiple different images ontop of each other but I will have to place them next to each other and have them be visible or not, but that will take up space on the dashboard, which is why the layering ontop of each other would've been a better way. 

I will look into the HTML idea.

It's unfortunate, though, because the transparancy slider is already doing the trick, when you insert an image through a blank button. It's just manual. I figured if that slider is doing that, there should be a way to control the slider through a command through DAX.

 

Again, thank you.

 

Erol.

Hi there @ErolOld,

Just posting a follow-up: It turns out that you can use a bit of a hack set certain properties (including transparency) by editing the visual.json files when using PBIP format. You may well have come across this yourself!

 

I had been experimenting myself and also saw this post that covers this method.

 

I have attached a demo PBIX.

 

I set this up in my demo PBIX by:

  1. Create a Card (new) visual.
  2. Place a dummy measure on the visual (I went with a measure returning BLANK).
  3. Turn off Callout values > Values & Labels.
  4. Turn on Images > Image
  5. Add an Image from a file
  6. Set the transparency to a placeholder value.
  7. Create a measure that returns the desired transparency as an integer.
    Mine is Transparency Value Int.
  8. Save as PBIP and close Power BI Desktop.
  9. Locate the visual.json file corresponding to the Card (new) visual.
    <PBIPName>.Report\definition\pages\<PageID>\visuals\<VisualID>\visual.json
  10. Find the "transparency" property of the image and replace as shown below.
  11. Save visual.json, and reopen the PBIP in Power BI Desktop.
  12. When the parameter/measure value changes, the transparency should now change. However, making any manual change to Transparency settings in Power BI Desktop will reset it to a literal value.

Original literal transparency value (set to 51% transparency as an example):

"transparency": {
  "expr": {
	"Literal": {
	  "Value": "51D"
	}
  }
}

Updated measure-based transparency (Entity = table, Property = measure name):

"transparency": {
  "expr": {
	"Measure": {
	  "Expression": {
		"SourceRef": {
		  "Entity": "Transparency"
		}
	  },
	  "Property": "Transparency Value Int"
	}
  }
}

I'm sure other variations are possible with other visuals.

Hopefully this is enabled in the Power BI Desktop interface soon!

 

Regards

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
(Virus scan in progress ...)
OwenAuger
Super User
Super User

Hi @ErolOld 

One idea, which is a bit of a workaround, is to place a shape over the image with fill color set the same as the background colour but with alpha channel controlled by DAX.

 

This will give the appearance of the image's transparency being adjusted.

 

In my test PBIX, with the blue background, the Fill Color measure is:

 

Fill Color = 
VAR TransparencyPct =
    [Transparency Value]
RETURN
    "RGBA(57,115,176," & TransparencyPct & ")"

 

 

Example attached.

OwenAuger_0-1724405122518.pngOwenAuger_1-1724405179512.png

Would this work in your situation?

 

Another idea you could try: Use HTML Content or HTML Content Lite, and construct HTML with DAX to display the image appropriately.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
(Virus scan in progress ...)

Helpful resources

Announcements