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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Brassodin
New Member

Change bar colour depending on percentage change from trend line

Hello

 

What formula can I use in a custom column to give a sales value a number based on criteria below. I am checking percentage difference in sales for each period against budget for each period and wanting to to use a custom column to change the colour of the bar, just am not very good with DAX.

1) If sales for period is more than 10% under budget then the bar is red, example below is P02 (sales 15 budget 30 = 50% under budget = 1)

2) if sales for period is within 10% of budget then bar is amber, example below is P08 (sales 38 Budget 40 = 10% within budget) or P11 (sales 32 budget 30 = 10% within budget = 2)

3) If sales for period is more than 10% over budget then bar is green, example below is P06 (sales 41 budget 30 = 24% over budget = 3) 

 

Many thanks in advance

Carlo

Brassodin_2-1639067746028.png

 

 

 

 

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Brassodin ,

I created some data:

vyangliumsft_0-1639466402599.png

Here are the steps you can follow:

1. Create measure.

Measure =
DIVIDE(
    MAX('MainTable'[Sales]),MAX('MainTable'[Budget])) -1
color =
SWITCH(
    TRUE(),
    [Measure] >= -0.5 && [Measure]<-0.1,"#4CAF50",
    [Measure] >= -0.1 && [Measure]<=0.1,"#FFC107",
    [Measure] > 0.1,"#f44336")

2. Format – Data color – Default color – fx.

vyangliumsft_1-1639466402601.png

3. Enter Default color – Data colors.

Format by – Field value

Based on field – [measure]

vyangliumsft_2-1639466402602.png

4. Result:

vyangliumsft_3-1639466402604.png

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Brassodin ,

I created some data:

vyangliumsft_0-1639466402599.png

Here are the steps you can follow:

1. Create measure.

Measure =
DIVIDE(
    MAX('MainTable'[Sales]),MAX('MainTable'[Budget])) -1
color =
SWITCH(
    TRUE(),
    [Measure] >= -0.5 && [Measure]<-0.1,"#4CAF50",
    [Measure] >= -0.1 && [Measure]<=0.1,"#FFC107",
    [Measure] > 0.1,"#f44336")

2. Format – Data color – Default color – fx.

vyangliumsft_1-1639466402601.png

3. Enter Default color – Data colors.

Format by – Field value

Based on field – [measure]

vyangliumsft_2-1639466402602.png

4. Result:

vyangliumsft_3-1639466402604.png

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

parry2k
Super User
Super User

@Brassodin I discussed similar problem and you can check it in this video https://www.youtube.com/watch?v=l2MRTFReCX0

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.