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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
sandwichnova
New Member

Data Bars

Hi

I'm trying to put together some basic reports to make life easier. I'm fairly new to PowerBI so please forgive any stupid questions.


I'm trying to add data bars to a table with conditional formatting. But the bars are out of wack. I assume it's because the Maximum is set to the 'highest value'. Is there away to set this so that the maximum to Total Licenses?

 

Table.pngData Bars.png

2 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @sandwichnova 

There  is currently no option to base the length of the databars on another measure. The row with the biggest value will always have the longest bar. Alternatively, you can use SVG images but you will have to setup it up for every measure that you want the SVG images to be based on. Pleasee attached sample pbix

Data Bar SVG = 
VAR _Value = [RandomValue] -- Current row value
VAR MaxValue = CALCULATE([RandomValue], ALLSELECTED()) -- Maximum value
VAR BarWidth = ROUND(DIVIDE(_Value, MaxValue) * 100, 0) -- Bar width as a percentage
VAR _Text = FORMAT(_Value, "$#,#") -- Text to display inside the bar
VAR BarColor = IF(NOT(HASONEVALUE('Table'[Value])), "RGBA(0,0,0,0)", "#81C784") -- Light green bar color but transparent at the total level
VAR TextColor = "black" -- Text color
VAR __Prefix = "data:image/svg+xml;utf8,"
VAR __Font = "Arial, sans-serif" -- Font family
VAR BarHeight = 12 -- Adjust the height of the bar
VAR BarYPosition = 5 -- Adjust the vertical starting point of the bar

RETURN
    __Prefix & "<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='" & BarHeight + 5 & "'>
        <rect x='0' y='" & BarYPosition & "' width='" & BarWidth & "%' height='" & BarHeight & "' fill='" & BarColor & "' />
        <text x='50%' y='" & (BarYPosition + BarHeight / 2) & "' fill='" & TextColor & "' font-size='8' font-family='" & __Font & "' text-anchor='middle'>" & _Text & "</text>
    </svg>"

danextian_0-1733293212645.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Anonymous
Not applicable

Hi @sandwichnova ,

 

Provide another method.

First construct a table like this:

vcgaomsft_1-1734573730229.png

Then create a new measure:

Total Assigned Licenses = 
VAR __curr_product = SELECTEDVALUE('Table 2'[Product Title])
VAR __result = 
SWITCH(
    TRUE(),
    ISBLANK(__curr_product), CALCULATE(SUM('Table'[Assigned Licenses]), ALL()),
    __curr_product="Total", CALCULATE(SUM('Table'[Assigned Licenses]), ALL()),
    CALCULATE(SUM('Table'[Assigned Licenses]),'Table'[Product Title]=__curr_product)
)
RETURN
    __result

Output:

vcgaomsft_0-1734573539734.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @sandwichnova ,

 

Provide another method.

First construct a table like this:

vcgaomsft_1-1734573730229.png

Then create a new measure:

Total Assigned Licenses = 
VAR __curr_product = SELECTEDVALUE('Table 2'[Product Title])
VAR __result = 
SWITCH(
    TRUE(),
    ISBLANK(__curr_product), CALCULATE(SUM('Table'[Assigned Licenses]), ALL()),
    __curr_product="Total", CALCULATE(SUM('Table'[Assigned Licenses]), ALL()),
    CALCULATE(SUM('Table'[Assigned Licenses]),'Table'[Product Title]=__curr_product)
)
RETURN
    __result

Output:

vcgaomsft_0-1734573539734.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

danextian
Super User
Super User

Hi @sandwichnova 

There  is currently no option to base the length of the databars on another measure. The row with the biggest value will always have the longest bar. Alternatively, you can use SVG images but you will have to setup it up for every measure that you want the SVG images to be based on. Pleasee attached sample pbix

Data Bar SVG = 
VAR _Value = [RandomValue] -- Current row value
VAR MaxValue = CALCULATE([RandomValue], ALLSELECTED()) -- Maximum value
VAR BarWidth = ROUND(DIVIDE(_Value, MaxValue) * 100, 0) -- Bar width as a percentage
VAR _Text = FORMAT(_Value, "$#,#") -- Text to display inside the bar
VAR BarColor = IF(NOT(HASONEVALUE('Table'[Value])), "RGBA(0,0,0,0)", "#81C784") -- Light green bar color but transparent at the total level
VAR TextColor = "black" -- Text color
VAR __Prefix = "data&colon;image/svg+xml;utf8,"
VAR __Font = "Arial, sans-serif" -- Font family
VAR BarHeight = 12 -- Adjust the height of the bar
VAR BarYPosition = 5 -- Adjust the vertical starting point of the bar

RETURN
    __Prefix & "<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='" & BarHeight + 5 & "'>
        <rect x='0' y='" & BarYPosition & "' width='" & BarWidth & "%' height='" & BarHeight & "' fill='" & BarColor & "' />
        <text x='50%' y='" & (BarYPosition + BarHeight / 2) & "' fill='" & TextColor & "' font-size='8' font-family='" & __Font & "' text-anchor='middle'>" & _Text & "</text>
    </svg>"

danextian_0-1733293212645.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.