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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Highlight matrix rows when column values are different

I have a scenario where I would like to highlight the values in a matrix visual where they are different in the same row. My source data looks like this:

 

CategorySubCategoryProductKey
AAA1X1
AAA2X2
BBB1Y1
BBB2Y1

 

My desired output (matrix):

CategorySubCategoryProduct 1Product 2
AAAX1X2
BBBY1Y1

 

With my real dataset, I have many more products than 2, so I would like to avoid doing any hard-coding of the product names in DAX (as I've seen in other solutions to similar problems).

 

I wrote a measure to to compare the min and max of the keys by category and subcategory, but it doesn't seem to work as expected when I try to use it for conditional formatting. That code looks like this:

 

 

diff_flag = 
var minKey = 
    CALCULATE(
        MINX(my_table,my_table[Key]),
       ALLEXCEPT(my_table,my_table[Category],my_table[SubCategory]))
var maxKey = 
    CALCULATE(
        MAXX(my_table,my_table[Key]),
        ALLEXCEPT(my_table,my_table[Category],my_table[SubCategory]))
var keyMatchBool = IF(minKey = maxKey , 1, 0)
return keyMatchBool

 

 

I tried to follow the solution outlined here, but ran into trouble because my Key field is no numeric.

 

Any help is appreciated!

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous,

 

Try this measure:

 

diff_flag = 
// get row count for each Category/SubCategory
VAR vRowCount =
    CALCULATE (
        COUNTROWS ( my_table ),
        ALLSELECTED ( my_table ),
        VALUES ( my_table[Category] ),
        VALUES ( my_table[SubCategory] )
    )
// get row count for each Category/SubCategory/Key
VAR vRowCountKey =
    COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( my_table, my_table[Category], my_table[SubCategory], my_table[Key] ),
            // remove filter context from matrix columns
            ALLSELECTED ( my_table[Product] )
        )
    )
VAR vResult =
    IF ( vRowCount = vRowCountKey, 0, 1 )
RETURN
    vResult

 

DataInsights_0-1676561151579.png

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@Anonymous,

 

Try this measure:

 

diff_flag = 
// get row count for each Category/SubCategory
VAR vRowCount =
    CALCULATE (
        COUNTROWS ( my_table ),
        ALLSELECTED ( my_table ),
        VALUES ( my_table[Category] ),
        VALUES ( my_table[SubCategory] )
    )
// get row count for each Category/SubCategory/Key
VAR vRowCountKey =
    COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( my_table, my_table[Category], my_table[SubCategory], my_table[Key] ),
            // remove filter context from matrix columns
            ALLSELECTED ( my_table[Product] )
        )
    )
VAR vResult =
    IF ( vRowCount = vRowCountKey, 0, 1 )
RETURN
    vResult

 

DataInsights_0-1676561151579.png

 





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

Proud to be a Super User!




Anonymous
Not applicable

This works! Can you help me understand a little bit better what the code is doing? So we're counting the number rows for each category/subcategory group, then counting the number of rows for each category/subcategory/key group and comparing the two?

@Anonymous,

 

Glad to hear that works. That's correct, it's a row count comparison of category/subcategory vs. category/subcategory/key. The SUMMARIZE function performs a Group By of category/subcategory/key (ALLSELECTED removes product filter context coming from the matrix). If the Group By reduces the row count, it means the key repeats in multiple rows.





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

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors