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
Anonymous
Not applicable

Highlighting the max and min values of a row in a matrix using Date table

I have a sales table, a date table and a department table. I want to highlight the maximum and minimum sales amount across the selected dates by the departments.

I have the following sales table.

 

MonthYearDeptSalesMonth_Year

MonthYearDeptSalesMonth_Year
12020A102020.01
22020A202020.02
32020A302020.03
42020A402020.04
52020A102020.05
12021A22021.01
22021A302021.02
32021A402021.03
42021A502021.04
52021A102021.05
12020B202020.01
22020B302020.02
32020B1002020.03
42020B1202020.04
52020B802020.05
62020B902020.06
12021B402021.01
22021B602021.02
32021B902021.03
42021B802021.04
52021B1002021.05
62021B402021.06

 

I also have a following date table:

MonthYearMonth_Year

MonthYearMonth_Year
120202020.01
220202020.02
320202020.03
420202020.04
520202020.05
620202020.06
720202020.07
820202020.08
920202020.09
1020202020.1
1120202020.11
1220202020.12
120212021.01
220212021.02
320212021.03
420212021.04
520212021.05
620212021.06
720212021.07
820212021.08
920212021.09
1020212021.1
1120212021.11
1220212021.12

 

Lastly, I also have a department table:

 

Dept
A
B
C

 

I am getting the following result:

samkaluskar_0-1690902991323.png

I am looking to get the following result:

samkaluskar_1-1690903027694.png

 

Following is my DAX code for highlighting min and max value (Note: I must use the Month_Year column from the date table):

MinMax = 
VAR Vals = 
    CALCULATETABLE(
        ADDCOLUMNS (
            SUMMARIZE ( Sales, 'Date'[Month_Year] ),
            "@SalesAmt", sum(Sales[Sales])
        ),
        ALLSELECTED ( 'Date'[Month_Year] )
    )
VAR MinValue = MINX ( Vals, [@SalesAmt] )
VAR MaxValue = MAXX ( Vals, [@SalesAmt] )
VAR CurrentValue = sum(Sales[Sales])
VAR Result = 
    SWITCH ( 
        TRUE,
        CurrentValue = MinValue, 1, -- 1 for MIN
        CurrentValue = MaxValue, 2  -- 2 for MAX
    )
RETURN
    Result

 

 

 

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , Create below measure and use in conditional formatting using field value option

 

MinMax =
VAR MinValue = calculate(MINX ( values('Date'[Month_Year]), calculate(sum(Sales[Sales]) )), ALLSELECTED ( 'Date'[Month_Year] ))
VAR MaxValue = calculate(MAXX ( values('Date'[Month_Year]), calculate(sum(Sales[Sales]) )), ALLSELECTED ( 'Date'[Month_Year] ))
VAR CurrentValue = sum(Sales[Sales])
VAR Result =
SWITCH (
TRUE,
CurrentValue = MinValue, "Red", -- 1 for MIN
CurrentValue = MaxValue, "Green" -- 2 for MAX
)
RETURN
Result

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.