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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DAX_merchant
Helper II
Helper II

conditional formatting with measure

I have a bar chart that shows a distribution. I would like to create a measure that returns one color for bars that fall within a certain value. 

If my distribution is from 0-1, I would like to have a measure that colors the bar falling between 0.1 and 0.2 a different color, but this range should be dynamic based on a user selection in a slicer, so it can't be hard coded in a rule, must be a field. 

 

Is this possible? Currently, I have not thought of a way as you need to wrap in an iterator to be able to refernce the specific value in a column (x axis is created using generateseries), and this will just return the first value comparission:

 

sumx(distribution, var currentrow = distribution[values] 

          return if(currentrow = 0.1, color 1, color 2))

will just return color 2 unless the value is 0.1. Does that make sense?

 

Thank you. 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @DAX_merchant 

I would like to apologize for the belated reply.

 

My sample:

vxuxinyimsft_0-1706003026037.png

 

I've modified the formula.

color =
IF (
    SELECTEDVALUE ( slicer[distribution] ) = BLANK (),
    "blue",
    IF (
        SELECTEDVALUE ( 'Table'[distribution] ) + 0.1
            = SELECTEDVALUE ( slicer[distribution] )
            || SELECTEDVALUE ( 'Table'[distribution] ) - 0.1
                = SELECTEDVALUE ( slicer[distribution] ),
        "yellow",
        "blue"
    )
)

 

vxuxinyimsft_1-1706003093013.png

 

vxuxinyimsft_2-1706003110222.png

Is this the result you expect?

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: 

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Please remove any sensitive data in advance.

 

Best Regards,
Community Support Team _Yuliax

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @DAX_merchant 

 

You can try the following steps.

 

1. Create a measure as follows.

 

Measure = IF(SELECTEDVALUE('Table'[distribution]) >= 0.1 && SELECTEDVALUE('Table'[distribution]) <= 0.2, "yellow", "blue")

 

 

2. With this clustered bar chart selected, I did what is shown here.

vxuxinyimsft_0-1705559818858.png

 

vxuxinyimsft_2-1705559857779.png

 

 

 

vxuxinyimsft_3-1705559928585.png

Is this the result you expect?

 

Best Regards,
Community Support Team _Yuliax

 

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

Thank you very much for this explanation @Anonymous . I apologize as I was too vague with my inquiry. In the end, this should be based on a unique identifier for a store. 

 

The histogram is created with a 0 - 1 distribution on the x axis while the y axis is a countx of stores. I thought innitially that one could highlight based on selectedvalue of the store, but there is no identifying information in the countx. 

 

This 0-1 distribution is based on a metric, such as % of sales a store contributes to a certain product. So my idea was instead of going off store ID, I could go off the metric itself, and highlight based on x axis instead of y axis. So I fetch the value for the metric in a measure for the selected store, then if it is within +- 0.01 of that selected stores metric, that column is highlighted. 

 

I will try the code you wrote, but it seems like this is hard coded for 0.1 and 0.2, and would only color if the user selects something in that range. Really, I want the user selection to be the thing that is colored. So even if we ignore the extra layer of the stores, is is possible to have a measure that takes selectedvalue of slicer from 0-1 and highlight the bars in that range? So user selects a value of 0.3, the bar with x axis value 0.3 is selected. 

Anonymous
Not applicable

Hi @DAX_merchant 

I would like to apologize for the belated reply.

 

My sample:

vxuxinyimsft_0-1706003026037.png

 

I've modified the formula.

color =
IF (
    SELECTEDVALUE ( slicer[distribution] ) = BLANK (),
    "blue",
    IF (
        SELECTEDVALUE ( 'Table'[distribution] ) + 0.1
            = SELECTEDVALUE ( slicer[distribution] )
            || SELECTEDVALUE ( 'Table'[distribution] ) - 0.1
                = SELECTEDVALUE ( slicer[distribution] ),
        "yellow",
        "blue"
    )
)

 

vxuxinyimsft_1-1706003093013.png

 

vxuxinyimsft_2-1706003110222.png

Is this the result you expect?

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: 

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Please remove any sensitive data in advance.

 

Best Regards,
Community Support Team _Yuliax

 

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors