cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dididing2001
Frequent Visitor

Highlight max value for each row in a matrix

I am trying to create a Power BI matrix and highlight the max value of each row to show the peak hour. 

Here is the matrix I made and the related fields:

dididing2001_3-1634492657747.png

dididing2001_1-1634492549093.png

dididing2001_2-1634492580376.png

I made a measure to find the max value for each day by modifying the original one of Alberto Ferrari (https://www.sqlbi.com/articles/highlighting-the-minimum-and-maximum-values-in-a-power-bi-matrix/)

My code is:

max_highlight = 
VAR Vals =
    CALCULATETABLE(
        ADDCOLUMNS (
            SUMMARIZE ( 'pickup_dropoff', 'pickup_dropoff'[DayName], 'pickup_dropoff'[hour] ),
            "PeakHour", SUMX (pickup_dropoff, 'pickup_dropoff'[frequency] )
        ),
        ALLSELECTED ('pickup_dropoff'[DayName])
    )

VAR MaxValue = MAXX ( Vals, [PeakHour] )
VAR CurrentValue = SUMX('pickup_dropoff', 'pickup_dropoff'[frequency] )
VAR Result =
    SWITCH (
        TRUE,
        CurrentValue = MaxValue, 2 -- 2 for MAX
    )
RETURN
    Result

I expected the max value would be colored red. For example, for Sunday, the number 424014 will be highlighted. For Monday, it will be 479349, and so on.

However, what I received after conditional formatting is a red matrix - all values were highlighted.

dididing2001_4-1634493104180.png

I appreciate it very much if anyone can point out what was wrong with my code.

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@dididing2001 

I create a measure for the conditional Formatting as follows, modify your table and column names as per your model. I also attached the file below my signature.

MaxInRow = 
VAR __MaxUnits = 
MAXX(
    ALLSELECTED( Data[Month Number] ),
    [Total Units]
)
RETURN
IF( 
    [Total Units] = __MaxUnits,
    "RED"
)

 

Fowmy_0-1634494851440.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@dididing2001 

I create a measure for the conditional Formatting as follows, modify your table and column names as per your model. I also attached the file below my signature.

MaxInRow = 
VAR __MaxUnits = 
MAXX(
    ALLSELECTED( Data[Month Number] ),
    [Total Units]
)
RETURN
IF( 
    [Total Units] = __MaxUnits,
    "RED"
)

 

Fowmy_0-1634494851440.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi - I am trying to solve a very simliar problem, but my date (which I represent as a year) comes from a date table separate from my table with my data. I can't figure out what I am doing wrong here.  Can you help me figure out how to write this? 


@Fowmy Your solution works like a charm! Thank you so much.

The measure works fine, and when I put the week filter on, the highlight also changes. This is definitely what I'm looking for.

dididing2001_0-1634496030872.png

 

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!