The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi all. I'm trying to use DAX to build a fun animated bar chart to be used in a table. The goal is to add a bar to each line in the table that changes colour based on if the pipeline is greater or smaller than the target for each item in the table.
I've already successfully made the bar to be sized correctly depending on how much ahead of target or behind the item is. The bar also changes colour to a yellow gradient if behind target, and blue gradient for every item ahead of target. So far all good.
My challenge now is to make sure that the "Total" line does not show the SVG rendered animation.
Any tips on how to do this?
Current DAX
SVG PBO vs Target =
VAR SVGWidth = 100
VAR SVGHeight = 12
VAR _PipelineMin = MINX( ALLSELECTED( Accounts[Customer ID] ) , [Pipeline($)] )
VAR _TargetMin = MINX( ALLSELECTED( Accounts[Customer ID] ) , [Target ($)] )
VAR _PipelineMax = MAXX( ALLSELECTED( Accounts[Customer ID] ) , [Pipeline ($)] )
VAR _TargetMax = MAXX( ALLSELECTED( Accounts[Customer ID] ) , [Target ($)] )
VAR _RangeMin = MIN( _PipelineMin , _TargetMin )
VAR _RangeMax = MAX( _PipelineMax , _TargetMax ) *1.2 //Adds a little extra space)
VAR PipelineBarWidth = ( DIVIDE( [Pipeline ($)] - _RangeMin , _RangeMax - _RangeMin ) ) * SVGWidth
VAR TargetBarWidth = ( DIVIDE( [Target ($)] - _RangeMin , _RangeMax - _RangeMin ) ) * SVGWidth
VAR Definitions =
"<defs>
<linearGradient x1='-61.5225' y1='108.592' x2='148.402' y2='227.408' gradientUnits='userSpaceOnUse' spreadMethod='reflect' id='fill0'>
<stop offset='0' stop-color='#E6AD10' />
<stop offset='0.5' stop-color='#D7950F' />
<stop offset='1' stop-color='#C87E0E' />
</linearGradient>
<linearGradient x1='43.5' y1='241.719' x2='43.5' y2='-1.71875' gradientUnits='userSpaceOnUse' spreadMethod='reflect' id='stroke1'>
<stop offset='0' stop-color='#50E6FF' stop-opacity='0' />
<stop offset='1' stop-color='#50E6FF' />
</linearGradient>
<linearGradient x1='-33.3955' y1='147.875' x2='120.395' y2='92.1256' gradientUnits='userSpaceOnUse' spreadMethod='reflect' id='fill2'>
<stop offset='0' stop-color='#3CCBF4' />
<stop offset='0.25' stop-color='#219AD8' />
<stop offset='0.75' stop-color='#086CBE' />
<stop offset='0.91' stop-color='#0669BC' />
<stop offset='1' stop-color='#0669BC' />
</linearGradient>
</defs>"
VAR TargetBarAnimation =
"<animate attributeName='width' from='0' to='"& TargetBarWidth &"' dur='2s' fill='freeze' />"
VAR PipelineBarAnimation =
"<animate attributeName='width' from='0' to='"& PipelineBarWidth &"' dur='2s' fill='freeze' />"
VAR TargetBar =
"<rect x='0' y='0' width='"& TargetBarWidth &"' height='"& SVGHeight &"' fill='url(#fill0)' rx='5' ry='5'>
"& TargetBarAnimation &"
</rect>"
VAR PipelineBar =
"<rect x='0' y='0' width='"& PipelineBarWidth &"' height='"& SVGHeight &"' fill='url(#fill2)' rx='5' ry='5'>
"& PipelineBarAnimation &"
</rect>"
VAR Img =
"
data:image/svg+xml;utf8, <svg width='"& SVGWidth &"' height='"& SVGHeight &"' xmlns='http://www.w3.org/2000/svg'>
"& Definitions &
TargetBar & // Draw target bar first
PipelineBar & // Draw pipeline bar in front
"</svg>
"
RETURN
IF(
NOT ISBLANK( [Target ($)] ),
Img
)
Use ISINSCOPE or HASONEVALUE to restrict the output to when you are in the rows, not in the totals.
How would you incorporate that? 😊
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |