Forum Discussion
Combine Table & Stacked Bar Chart
OK this was what I was able to pull together. It's rough and needs work. I couldn't understand how the Age Group column factored in to this so I just kind of went with some data. I'll give you the code. It "works", it's not what I would call pretty. Attached a PBIX but you won't be able to open it unless you upgrade to April 2020.
SVG Stacked Data Bar =
VAR __Table = 'Table'
VAR __Total = MAX('Table'[Average of Duration]) + MAX('Table'[count of projects])
VAR __Color1 = IF(MAX('Table'[Average of Duration]) > MAX('Table'[count of projects]),"Red","Green")
VAR __Color2 = IF(MAX('Table'[Average of Duration]) > MAX('Table'[count of projects]),"Green","Red")
VAR __Min = MIN(MAX('Table'[Average of Duration]),MAX('Table'[count of projects]))
VAR __ShapeWidth2 = __Min / __Total * 500
VAR __header = "data:image/svg+xml;utf8," &
"<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='" & "500" & "' height='210'>"
VAR __footer = "</svg>"
VAR __shapeTextSquare1 = "<polygon points=""0,200 " & "500" & ",200 " & "500" & ",0 0,0"" style=""fill:" & __Color1 & ";stroke:" & __Color1 & ";stroke-width:0;fill-rule:evenodd;"" />"
VAR __shapeTextSquare2 = "<polygon points=""0,200 " & __ShapeWidth2 & ",200 " & __ShapeWidth2 & ",0 0,0"" style=""fill:" & __Color2 & ";stroke:" & __Color2 & ";stroke-width:0;fill-rule:evenodd;"" />"
VAR __SVG = __header & __shapeTextSquare1 & __shapeTextSquare2 & __footer
RETURN
__SVG
I just created a new measure and applied your code. I am getting the text only instead of bars.
- Anonymous6 years agoNot applicable
- Greg_Deckler6 years ago
Community Champion
Oh, sorry Anonymous - you need to set the Data Category for the measure/column to Image URL. Click on the measure/column and then click on the Measure Tools or Column Tools. Change the Date Category to Image URL.
- Anonymous6 years agoNot applicable
Greg_Deckler , I am not seeing any image now. I followed your options. I changed like Model --> Selected 'SVG' column --> Advanced --> Data Category --> Image URL
- Greg_Deckler6 years ago
Community Champion
Another trick, if your rows come out really really tall, you can edit the Image Height in the Grid area of the visual.