• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

number coloring positive green negative red in card visual in power bi|Dashboards & Charts|Excel Forum|My Online Training Hub

You are here: Home / number coloring positive green negative red in card visual in power bi|Dashboards & Charts|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumDashboards & Chartsnumber coloring positive green nega…
sp_PrintTopic sp_TopicIcon
number coloring positive green negative red in card visual in power bi
Avatar
Yuan Zhang
Member
Members
Level 0
Forum Posts: 32
Member Since:
December 2, 2021
sp_UserOfflineSmall Offline
1
May 4, 2023 - 6:22 am
sp_Permalink sp_Print sp_EditHistory

hi all,

How can I make the number coloring based on the value (positive green negative red) in card visual in power bi? I found this post but my codes don't seem to work? I never did HTML codes. so something wrong there? Or do you have other solutions? Thank you!

In my code (code-in-the-video.PNGImage Enlarger

visual-result.PNGImage Enlarger
my-code.PNGImage Enlarger
VAR var_Volume_Current_Year_vs_Last_Year = CALCULATE(SUM(T_Production_Volume[Volume in Ton]),FILTER(T_Production_Volume,T_Production_Volume[Current FY?]= "Current Year"))-CALCULATE(SUM(T_Production_Volume[Volume in Ton]),FILTER(T_Production_Volume,T_Production_Volume[Current FY?]= "Budget"))

) is an existing measure calculation is  correct, so no error with that part I think.
sp_PlupAttachments Attachments
  • sp_PlupImage code-in-the-video.PNG (113 KB)
  • sp_PlupImage visual-result.PNG (39 KB)
  • sp_PlupImage my-code.PNG (30 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
2
May 4, 2023 - 9:53 am
sp_Permalink sp_Print sp_EditHistory

Hi,

I wrote about this topic here Conditional Formatting in Power BI

You can do this 2 ways:

1) Using formatting based on rules

2) Using formatting based on a field value

 

Using rules is easier to set up but can be less reliable as you have to explicitly say what the smallest and largest value in your data are, and this might not be known, or change.

 

To set up formatting based on a rule

1. Add the card

2. Add the value to the card

3. Go to Format Visual -> Callout value -> click on the fx button

4. Add a rule like this then click OK

conditional formatting using a ruleImage Enlarger

 

This is using the values calculated in the DAX measure you have already written, in my case I've named that measure Difference Using Rules CF and the code for that is

 

Difference Using Rules CF = SUM('Actuals & Budget'[Actuals]) - SUM('Actuals & Budget'[Budget])

 

Formatting based on Field Value

This method requires you to write a separate DAX measure to choose what color to apply to the visual

That DAX looks like this

 

Difference Using Field CF =
VAR _diff = SUM('Actuals & Budget'[Actuals]) - SUM('Actuals & Budget'[Budget])
RETURN
IF (_diff >= 0, "green", "red")
 

 

To use this to set the color of the card text:

1. Add the card

2. Add the value to the card (this is the same DAX measure used in method 1 to calculate difference between Budget and Actual)

3. Go to Format Visual -> Callout value -> click on the fx button

4. Add this then click OK

conditional formatting using dax measureImage Enlarger

 

Either method will give you the colors you want in your card. 

green color for numberImage Enlarger

 

red color for negative numberImage Enlarger

 

I prefer the 2nd approach as having a separate DAX measure to set colors is more flexible if you need to change or add colors or alter the values to which those colors should be applied.

Download my sample PBIX file for examples of both methods described here.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Yuan Zhang
Member
Members
Level 0
Forum Posts: 32
Member Since:
December 2, 2021
sp_UserOfflineSmall Offline
3
May 4, 2023 - 7:20 pm
sp_Permalink sp_Print

Thank you so much Phil! Both ways work fine!! Have a great day!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.