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
samkaluskar
Frequent Visitor

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

@samkaluskar , 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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.