skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
    • Getting started
      • Overview
      • Online workshops
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • Field Parameters- Conditional Formatting

    Field Parameters- Conditional Formatting

    10-12-2022 20:49 PM - last edited 11-24-2022 01:03 AM

    Super User amitchandak
    Super User
    426 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    amitchandak
    Super User amitchandak
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Field Parameters- Conditional Formatting

    ‎10-12-2022 08:49 PM

    Field Parameters- Conditional Formatting

    Power BI(15).jpg

    Problem Description: While using Field Parameters, we want to do conditional formatting using the selected Axis of the selected measure value.

    Model: I am using the standard sales model, which I am using for all my videos and blogs. Sales fact with a key measure [net], joined with dimensions: Item, Geography, Date, and Customer.

    amitchandak_0-1665632281111.png

     

    Solution: We need to get the selected value of the Axis or Measure field parameters and use that in field conditional formatting using a color measure. 

    Created Axis Field Parameters

    Axis Slicer = {
    ("Brand", NAMEOF('Item'[Brand]), 0),
    ("Category", NAMEOF('Item'[Category]), 1),
    ("Sub Category", NAMEOF('Item'[Sub Category]), 2),
    ("State", NAMEOF('Geography'[State]), 3),
    ("City", NAMEOF('Geography'[City]), 4)
    }

    Created Measure Field Parameters

    Measure Slicer = {
    ("Net", NAMEOF('Measure'[Net]), 0),
    ("Gross", NAMEOF('Measure'[Gross]), 1),
    ("COGS", NAMEOF('Measure'[COGS]), 2),
    ("Discount", NAMEOF('KPI'[Discount]), 3),
    ("Discount %", NAMEOF('Measure'[Discount %]), 4),
    ("Margin %", NAMEOF('Measure'[Margin %]), 5)
    }

    Created a dynamic visual using that

    amitchandak_1-1665632281113.png

     

    Field Parameters

    Create a selected value for the axis and measure the slicers 

    Selected Axis = maxx(FILTER('Axis Slicer', 'Axis Slicer'[Axis Slicer Order] = SELECTEDVALUE('Axis Slicer'[Axis Slicer Order])), 'Axis Slicer'[Axis Slicer])
    Selected Measure = maxx(FILTER('Measure Slicer', 'Measure Slicer'[Measure Slicer Order] = SELECTEDVALUE('Measure Slicer'[Measure Slicer Order] )), 'Measure Slicer'[Measure Slicer])

    These are only for the single value selection. 

    amitchandak_2-1665632281114.png

     

    The color measures are

    Axis Color = Switch([selected Axis],
    "Brand", "Red",
    "Category", "Blue",
    "Sub Category", "Green",
    "State", "Yellow",
    "City", "Grey"
    )
    Measure Color = Switch([Selected Measure],
    "Net", "Red",
    "Gross", "Blue",
    "COGS", "Green",
    "Discount", "Yellow",
    "Discount %", "Grey",
    "Margin %", "Purple"
    )

    Then this is how it looks like, Axis Color (Page1)

    amitchandak_3-1665632281123.png

     

    Axis Color

    Measure Color, on another visual (Page2)

    amitchandak_4-1665632281122.png

     

    Measure Color

    You can combine both the selected measure and selected axis code and have more complex conditional formatting. Try that out

    You can also force the measure’s value-based conditional formatting on selected measure example

    Measure Color = Switch([Selected Measure],
    "Net", "Red",
    "Gross", "Blue",
    "COGS", "Green",
    "Discount", "Yellow",
    "Discount %", "Grey",
    "Margin %", Switch(True(), [Margin %] <.125, "Pink", "Purple")
    )
    amitchandak_5-1665632281122.png

     

    Measure value-based conditional formatting

     

    File is attached below.

     

    Find all my Medium blogs here

    Click Here to access all my blogs and videos in a jiffy via an exclusive visual glossary using Power BI.
    Please like, share, and comment on these. Your suggestions on improvement, challenges, and new topics will help me explore more.

    You Can watch my Power BI Tutorial Series on My Channel, Subscribe, Like, and share

    Master Power BI

    Expertise Power BI

    Power BI For Tableau User

    DAX for SQL Users



    Learn Power BI - Full Course with Dec-2022, with new DAX functions like Window, Index, Offset !!
    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
    Formatted Profit and Loss Statement with empty lines
    Power Bi Field Parameter Conditional formatting.pbix
    Labels:
    • Labels:
    • Mathematical
    • Other
    Message 1 of 2
    426 Views
    2
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    Clem_Fandango
    Clem_Fandango Advocate I
    Advocate I
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-19-2022 08:43 AM

    Thank you so much for this. 
    I was trying all sorts of possible solutions for my "conditional formatting dependent on selected measure in the field parameter problem" using a combination of ISSELECTEDMEASURE,  SELECTEDVALUE & SWITCH statements amongst others but just couldn't get it to work.
    I wish I'd just googled it 1st! 😄 
    Thanks Again for the article. 

     

    Message 2 of 2
    328 Views
    0
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices