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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
pabeader
Post Patron
Post Patron

Conditional Formatting of individual bars in bar chart EDIT I figured out what I was doing wrong.

I have the following data:

 

Sort Order | Item       

1                |Product1

2                |Product2 

3                |Product3

4                |Product4 

 

 

Item        | Quantity

Product1 | 213

Product2 | 145

Product3 | 312

Product4 | 274

 

I would like to show the data as a bar chart.  The bar for Product3 should be Green if it is greater than Product2, Red if it's not.  The bar for Product2 should be Green if it's greater than Product1, Red if it's not.  The other bars  should be some other color like Blue.

 

I've tried a number of different combinations of measures but I just can't seem to figure this one out.  I feel like I know how to do it but the actual implimentation is beyond me.

 

 

EDIT:  Included Sorting Table...

1 ACCEPTED SOLUTION

@pabeader 

You must have more complex data table, but for this sample try following:
1. Create a conditional measure:

Measure = 
Var p1 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 1"))
var p2 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 2"))
var p3 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 3"))
var p4 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 4"))
Return 
SWITCH(TRUE(),
p3>p2,1,
p2>p1,1,
0)

2. Set default color to Red 

default color green.PNG

3. Rule with the measure

rule by measure.PNG

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@pabeader 

I believe the real dataset you have should be more detailed than this. Si there a numeric value associated with each Product Name like a sort order which will help identify the category value to avoid hard coding it?

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

The order that they appear in, doesn't really matter.  The different Products could appear anywhere in the chart, what matters is their relationship to each other.  Product3 > Product2 makes Product3 bar Green otherwise Red.  Product2 > Product1 makes Product2 bar Green otherwise Red.

@pabeader 

You must have more complex data table, but for this sample try following:
1. Create a conditional measure:

Measure = 
Var p1 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 1"))
var p2 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 2"))
var p3 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 3"))
var p4 = CALCULATE(SUM('Table (2)'[Quantity]),FILTER('Table (2)',[Item]="Product 4"))
Return 
SWITCH(TRUE(),
p3>p2,1,
p2>p1,1,
0)

2. Set default color to Red 

default color green.PNG

3. Rule with the measure

rule by measure.PNG

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Actually, the datatable is that simple.  It's the result of a number of aggregations and work on the SQL backend.

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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