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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Combine Table & Stacked Bar Chart

All,

 

I have a requirement to develop a report like below. Just removed the approver name due to security reason, think of some names under Approver.

 

tempsnip.png

This is not a single chart, i just added 2 charts table & stacked bar chart and applied 'sent back' for stacked bar chart. I have 3 slicers.

 

If i select only one or two names then the report looks like this.

 

tempsnip.png

 

tempsnip.png

But i am looking to align this bar straight to the name instead of shrinking to its entire size. is it possible?

26 REPLIES 26
Greg_Deckler
Super User
Super User

There is a 'data bars' option for matrix visualizations that people have used to create condensed bar charts like what you show. However, I do not believe that solution works for stacked bar charts. You could possibly do it with an SVG graphic. Like this for example: https://community.powerbi.com/t5/Quick-Measures-Gallery/SVG-Microchart-Harveyball-and-Harveybox/td-p...

 

If you provide sample data I could give this a whirl, it has been awhile since I created an SVG graphic so could be fun. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I didnt see 'Data bar' option in the Matrix visual. is this introduced in the latest version? I'm using quite old version for now.

 

2.71 (July 2019 Version) - Have to upgrade

 

Please find below the sample data. There is a custom column created for Age Group.

 

Age Group = IF(my[Duration] <= 3, "<=3 Days",IF (my[Duration] >3 && my[Duration] < 6,"> 3 and < 6 Days",">=6 Days"))
 
I used Approver, Count of ProjectID & Age Group for the "100% Stacked Bar Chart".

 

Approvercount of projectsAverage of Duration%3 Days Outstanding
a12323100%
a21102100%
a3210%
a4468100%
a518100%
a6123100%
a7118100%
a82210100%
a9410%
a10719100%
a111376100%
a121102100%
a13194695%
a141413975%
a1523750%
a16969100%
a1762333%
a18181100%
a19130%

 

 

Anonymous
Not applicable

It looks like SVG can be the solution for this, but it is bit complex to understand for me (As a beginer to PowerBI)

 

How about using R for this scenario? 

@Anonymous  - It is under Conditional Formatting oddly enough.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Yes, I Can see that option, but it looks like it will not fulfil my requirement.

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&colon;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

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

 

I just created a new measure and applied your code.  I am getting the text only instead of bars.

 

 
Anonymous
Not applicable

tempsnip.png

Another trick, if your rows come out really really tall, you can edit the Image Height in the Grid area of the visual.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not 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

 

tempsnip.png

Anonymous
Not applicable

I referred few other posts here and found the issue.

 

data&colon;

 

I changed it to data: 

Anonymous
Not applicable

It is fine, but i am looking for 3 colors based on 'Age Group'. I just implemented in the actual report, but i am getting 'MAX function only accepts a column reference as the argument number 1".

Anonymous
Not applicable

I tried my level best to bring the expected result.

 

SVG Stacked Data Bar =
VAR __Table = 'my'

VAR __Color1 = IF (AVERAGE(my[<3 age group])=1,"Green","Yellow") VAR __Color2 = IF (AVERAGE(my[<3 age group])=1,"Yellow","Green")
VAR __ShapeWidth2 = count(my[ProjectID])*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

Anonymous
Not applicable

SVG Stacked Data Bar =
VAR __Table = 'my'
 
VAR __Color1 = IF (AVERAGE(my[<3 age group])=1,"Green") VAR __Color2 = IF (AVERAGE(my[>3 & <6 group])=1,"Yellow","Red")
VAR __ShapeWidth2 = count(my[ProjectID])*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
 
tempsnip.png

i'm getting like above which is not correct.

 

'Age Group' is not applied, BAR length is also very small.

 

Anonymous
Not applicable

@Greg_Deckler , Can you look into the issue please and provide the solution?

It's going to be next to impossible to troubleshoot this without the data @Anonymous  - can you share the PBIX or a representative sample?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

 

Please find the mock data.

 

ApproverProjectIDDuration
a1p12
a1p24
a1p310
a2l11
a2l21
a2l31
a3f115
a3f215
a3f320
a3f420

 

Calcuated Columns/Measures:

projects>3 days = IF (my[Duration] >3, 1, 0)

count of projects = DISTINCTCOUNT(my[ProjectID])
%3 Days Outstanding = SUM(my[projects>3 days])/[count of projects]
Age Group = IF(my[Duration] <= 3, "<=3 Days",IF (my[Duration] >3 && my[Duration] < 6,"> 3 and < 6 Days",">=6 Days"))
Anonymous
Not applicable

@Greg_Deckler , is the same data help you to bring the expected result? can you help me on this ?

@Anonymous - Sorry, lost track of this thread. Let me take a look at the data you provided and see what I can create.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.