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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
MrSnaggls
Frequent Visitor

Getting max value for each row in matrix

Hi,

 

I have a problem which haunts me for some days now. It didn't look that hard at first, but it turned out challenging.

Overall target:
I have a matrix with 3 dimensions as rows and 1 dimensions as column. I want to make a measure to color these rows. For each row. the lowest value should be green and the highest value should be red. 
This has to happen for all 3 dimensions per row.
So i need to figure out the highest (and lowest) value per row and I have to put the value into this perspective. Once this is working properly, the rest should be easy.

 

Premises:
There are more dimensions like time I want to slice.
And also the dimension which I need for columns I need to slice to.

So the highest/lowest value needs to be evaluated in context of these slicers.

Raw Data as Matrix

MrSnaggls_1-1731406819569.png

 

Desired result for max value per row

MrSnaggls_2-1731406856792.png


My Approach
I built a test case with only 2 dimensions as rows.
a) Check if calculated value is on row 2 (not aggregated) or 1 aggregated. 

IF(
    HASONEVALUE(Test_Table[Row2]),
    SUMX(_SUM_Row2, [MAX_Row2]),
    IF(
        HASONEVALUE(Test_Table[Row1]),
        2, // Placeholder, Insert _SUM_Row1 here if concept for _SUM_Row2 is working
        BLANK()
    )
)


b) Use Combination of Summarize and MAX (or MAXA/MAXX) accordingly and get the max value (here only for Row2)

This is where I failed to create a proper formula and I dont want to share my half working formula.

Test Data:
I could share my set of test values, is there any possibility to upload an xlsx here?

Row1Row2Row3ColumnValueTime
AAAGreen41
AABGreen31
A21
AAAYellow71
AABYellow81
A101
AAABlue21
AABBlue41
A81
BBAGreen41
BBBGreen31
B21
BBAYellow71
BBBYellow81
B101
BBABlue21
BBBBlue41
B81
C...1
and so on     
AAAGreen42
AABGreen32
A22
AAAYellow72
and so on     


Thanks a lot in advance!

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@MrSnaggls,

 

Try these measures. The concept is to let the row fields naturally slice the data, but remove column filter context from within the visual (i.e. keep slicer/filter selections). You can use hex codes instead of color names.

 

Sum Value = SUM ( Test_Table[Value] )
Conditional Formatting = 
VAR vValue = [Sum Value]
// create table of all Column values per slicers/filters
VAR vColumnValues =
    CALCULATETABLE (
        VALUES ( Test_Table[Column] ),
        ALLSELECTED ( Test_Table[Column] )
    )
VAR vTable =
    ADDCOLUMNS ( vColumnValues, "@Value", [Sum Value] )
VAR vRowMinValue =
    MINX ( vTable, [@Value] )
VAR vRowMaxValue =
    MAXX ( vTable, [@Value] )
VAR vResult =
    SWITCH ( TRUE, vValue = vRowMinValue, "Green", vValue = vRowMaxValue, "Red" )
RETURN
    vResult

 

Apply conditional formatting using the measure [Conditional Formatting]:

 

DataInsights_0-1731420444775.png

 

DataInsights_1-1731420466845.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@MrSnaggls,

 

Try these measures. The concept is to let the row fields naturally slice the data, but remove column filter context from within the visual (i.e. keep slicer/filter selections). You can use hex codes instead of color names.

 

Sum Value = SUM ( Test_Table[Value] )
Conditional Formatting = 
VAR vValue = [Sum Value]
// create table of all Column values per slicers/filters
VAR vColumnValues =
    CALCULATETABLE (
        VALUES ( Test_Table[Column] ),
        ALLSELECTED ( Test_Table[Column] )
    )
VAR vTable =
    ADDCOLUMNS ( vColumnValues, "@Value", [Sum Value] )
VAR vRowMinValue =
    MINX ( vTable, [@Value] )
VAR vRowMaxValue =
    MAXX ( vTable, [@Value] )
VAR vResult =
    SWITCH ( TRUE, vValue = vRowMinValue, "Green", vValue = vRowMaxValue, "Red" )
RETURN
    vResult

 

Apply conditional formatting using the measure [Conditional Formatting]:

 

DataInsights_0-1731420444775.png

 

DataInsights_1-1731420466845.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.