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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
learner24
Regular Visitor

Highlight highest color on column chart using Field Parameters and conditional formatting

I have created a field parameters slicer named "Analysis" for different measures and used the field parameters table "Analysis" in the Y-axis of the column chart. The dynamic selection of slicer values is reflected in the column chart accordingly. Using conditional formatting, I want to highlight the highest value with one color and the rest of the columns with a common color. I created a measure with the formula below and applied it as fx in the column section. Upon applying and dynamic selection, it doesn't reflect the colors at the intended places as shown in the screenshot. How to fix this?

Formula:

HighlightMinMax =
VAR _CurrentValue = SELECTEDMEASURE()
VAR _MaxValue = MAXX(
    ALLSELECTED(Analysis),
    SELECTEDMEASURE()
)
RETURN
    IF(_CurrentValue = _MaxValue, "#38220f", "#967259")
 

Screenshots of the visual and table:

 

Screenshot 2024-11-05 163214.png

 

learner24_0-1730793036247.png

 

1 ACCEPTED SOLUTION
shafiz_p
Resident Rockstar
Resident Rockstar

Hi @learner24 
You measure will not work because SELECTEDMEASURE not work with field parameter rather it works with calculation group. You can debug by returning simply _CurrentValue and you will see the result is blank. 

Also you need to compare current value with the summarized value, other wise you would not be able to identify max value.

So to make it dynamic, you need to repeate same operation for each measure, then use selected value, compare using if or switch condition and return desired result.

Try this below code (I have only 2 measure, since you have 5, then repeate same operation for 5 of them):

MaxColumnColor = 
VAR _selectedMeasure = SELECTEDVALUE(Analysis[Analysis Order])

//For Revenue
VAR _ValueTableRev = CALCULATETABLE(ADDCOLUMNS(SUMMARIZE('Calendar', 'Calendar'[Month]), "@Rev", [Revenue]), ALLSELECTED())
VAR _MaxValueRev = MAXX(_ValueTableRev, [@Rev])
VAR _RevCol = SWITCH(TRUE(), [Revenue]=_MaxValueRev, "Green", "Gray")


//For Quantity
VAR _ValueTableQty = CALCULATETABLE(ADDCOLUMNS(SUMMARIZE('Calendar', 'Calendar'[Month]), "@Qty", [OrderQty]), ALLSELECTED())
VAR _MaxValueQty = MAXX(_ValueTableQty, [@Qty])
VAR _QtyCol = SWITCH(TRUE(), [OrderQty]=_MaxValueQty, "Purple", "Gray")


//Result
VAR _Result =
    SWITCH(
        TRUE(),
        _selectedMeasure = 0, _QtyCol,
        _selectedMeasure = 1, _RevCol,
        "Blue"
    )

RETURN
_Result

I have used Order of field parameter than name. It is easy.

Here is my desired output:

When Order Qty:

shafiz_p_0-1730810510868.png

 

When Revenue:

shafiz_p_1-1730810547708.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

 

Best Regards,
Shahariar Hafiz

 

View solution in original post

3 REPLIES 3
v-cgao-msft
Community Support
Community Support

Hi @learner24 ,

I assume that the x-axis of the histogram is Table[Bin].

MEASURE =
VAR __cur_measure_order =
    SELECTEDVALUE ( 'Analysis'[Parameter Order] )
VAR __max_total_customers =
    MAXX ( ALL ( 'Table'[Bin] ), [Total Customer] )
VAR __max_total_revenue =
    MAXX ( ALL ( 'Table'[Bin] ), [Total Revenue] )
VAR __max_total_rewards =
    MAXX ( ALL ( 'Table'[Bin] ), [Total Rewards] )
VAR __max_total_transactions =
    MAXX ( ALL ( 'Table'[Bin] ), [Total Transactions] )
VAR __max_avg_revenue =
    MAXX ( ALL ( 'Table'[Bin] ), [Average Revenue] )
VAR __max_avg_rewards =
    MAXX ( ALL ( 'Table'[Bin] ), [Average Rewards] )
VAR __result =
    SWITCH (
        __cur_measure_order,
        0, IF ( [Total Customer] = __max_total_customers, "#38220f", "#967259" ),
        1, IF ( [Total Revenue] = __max_total_revenue, "#38220f", "#967259" ),
        2, IF ( [Total Rewards] = __max_total_rewards, "#38220f", "#967259" ),
        3, IF ( [Total Transactions] = __max_total_transactions, "#38220f", "#967259" ),
        4, IF ( [Average Revenue] = __max_avg_revenue, "#38220f", "#967259" ),
        5, IF ( [Average Rewards] = __max_avg_rewards, "#38220f", "#967259" )
    )
RETURN
    __result

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

shafiz_p
Resident Rockstar
Resident Rockstar

Hi @learner24 
You measure will not work because SELECTEDMEASURE not work with field parameter rather it works with calculation group. You can debug by returning simply _CurrentValue and you will see the result is blank. 

Also you need to compare current value with the summarized value, other wise you would not be able to identify max value.

So to make it dynamic, you need to repeate same operation for each measure, then use selected value, compare using if or switch condition and return desired result.

Try this below code (I have only 2 measure, since you have 5, then repeate same operation for 5 of them):

MaxColumnColor = 
VAR _selectedMeasure = SELECTEDVALUE(Analysis[Analysis Order])

//For Revenue
VAR _ValueTableRev = CALCULATETABLE(ADDCOLUMNS(SUMMARIZE('Calendar', 'Calendar'[Month]), "@Rev", [Revenue]), ALLSELECTED())
VAR _MaxValueRev = MAXX(_ValueTableRev, [@Rev])
VAR _RevCol = SWITCH(TRUE(), [Revenue]=_MaxValueRev, "Green", "Gray")


//For Quantity
VAR _ValueTableQty = CALCULATETABLE(ADDCOLUMNS(SUMMARIZE('Calendar', 'Calendar'[Month]), "@Qty", [OrderQty]), ALLSELECTED())
VAR _MaxValueQty = MAXX(_ValueTableQty, [@Qty])
VAR _QtyCol = SWITCH(TRUE(), [OrderQty]=_MaxValueQty, "Purple", "Gray")


//Result
VAR _Result =
    SWITCH(
        TRUE(),
        _selectedMeasure = 0, _QtyCol,
        _selectedMeasure = 1, _RevCol,
        "Blue"
    )

RETURN
_Result

I have used Order of field parameter than name. It is easy.

Here is my desired output:

When Order Qty:

shafiz_p_0-1730810510868.png

 

When Revenue:

shafiz_p_1-1730810547708.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

 

Best Regards,
Shahariar Hafiz

 

Uzi2019
Super User
Super User

Hi @learner24 

 

I think this video might help you.

https://www.youtube.com/watch?v=IpTNX_MZLPs

 

https://www.youtube.com/watch?v=pWKfXIGFmK0

 

 

I hope I answered your question!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.