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

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

Reply
Anonymous
Not applicable

Comparing values in a row

Dear Community, 

I have a matrix with 1 row and 3 columns, and one value,
I wanted to compare values of each row , if all values are same, change the color of row to blue, if they are not same change it to gray, 
how can I handle this with DAX ? 

question.PNG

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try this:

Measure = 
VAR t1 =
    ADDCOLUMNS (
        ALLSELECTED ( 'Table' ),
        "Sum",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Rows] = MAX ( 'Table'[Rows] ) )
            )
    )
VAR Disc_C1 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns1] ), ALLSELECTED ( 'Table' ) )
VAR Disc_C2 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns2] ), ALLSELECTED ( 'Table' ) )
VAR Disc_C3 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns3] ), ALLSELECTED ( 'Table' ) )
VAR Disc_ =
    SWITCH (
        TRUE (),
        ISFILTERED ( 'Table'[Columns3] ) && ISFILTERED ( 'Table'[Columns2] )
            && ISFILTERED ( 'Table'[Columns1] ),
            Disc_C3 * Disc_C2 * Disc_C1,
        ISFILTERED ( 'Table'[Columns2] ) && ISFILTERED ( 'Table'[Columns1] ), Disc_C2 * Disc_C1,
        ISFILTERED ( 'Table'[Columns1] ), Disc_C1,
        ISFILTERED ( 'Table'[Columns3] )
            && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
                && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), Disc_C3,
        ISFILTERED ( 'Table'[Columns2] )
            && NOT ( ISFILTERED ( 'Table'[Columns3] ) )
                && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), Disc_C2,
        ISFILTERED ( 'Table'[Columns1] )
            && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
                && NOT ( ISFILTERED ( 'Table'[Columns3] ) ), Disc_C1
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Avg", [Sum] / Disc_ )
VAR Avg_ =
    AVERAGEX ( t2, [Avg] )
RETURN
    IF ( SUM ( 'Table'[Value] ) = Avg_, 0, 1 )
Measure 2 = 
SWITCH (
    TRUE (),
    ISFILTERED ( 'Table'[Columns3] ) && ISFILTERED ( 'Table'[Columns2] )
        && ISFILTERED ( 'Table'[Columns1] ),
        MAXX (
            ALLSELECTED ( 'Table'[Columns1], 'Table'[Columns2], 'Table'[Columns3] ),
            [Measure]
        ),
    ISFILTERED ( 'Table'[Columns2] ) && ISFILTERED ( 'Table'[Columns1] ), MAXX ( ALLSELECTED ( 'Table'[Columns1], 'Table'[Columns2] ), [Measure] ),
    ISFILTERED ( 'Table'[Columns1] ), MAXX ( ALLSELECTED ( 'Table'[Columns1] ), [Measure] ),
    ISFILTERED ( 'Table'[Columns3] )
        && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
            && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), MAXX ( ALLSELECTED ( 'Table'[Columns3] ), [Measure] ),
    ISFILTERED ( 'Table'[Columns2] )
        && NOT ( ISFILTERED ( 'Table'[Columns3] ) )
            && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), MAXX ( ALLSELECTED ( 'Table'[Columns2] ), [Measure] ),
    ISFILTERED ( 'Table'[Columns1] )
        && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
            && NOT ( ISFILTERED ( 'Table'[Columns3] ) ), MAXX ( ALLSELECTED ( 'Table'[Columns1] ), [Measure] )
)

Comparing values in a row.gif

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

frown.PNG

@Icey Thanks for your help. I got this error, Is it normal ? do you have any idea? 

 

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Just as the error mentioned, thereis not enough memory to complete this operation. Please try to: 

1. stop other irrelevant applications and services

2. Modify the measures like so:

 

Measure_1 = 
VAR t1 =
    SUMMARIZE (
        'Table',
        'Table'[Rows],
        'Table'[Columns1],
        'Table'[Columns2],
        'Table'[Columns3],
        'Table'[Value],
        "Sum",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Rows] = MAX ( 'Table'[Rows] ) )
            )
    )
VAR Disc_C1 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns1] ), ALLSELECTED ( 'Table' ) )
VAR Disc_C2 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns2] ), ALLSELECTED ( 'Table' ) )
VAR Disc_C3 =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Columns3] ), ALLSELECTED ( 'Table' ) )
VAR Disc_ =
    SWITCH (
        TRUE (),
        ISFILTERED ( 'Table'[Columns3] ) && ISFILTERED ( 'Table'[Columns2] )
            && ISFILTERED ( 'Table'[Columns1] ),
            Disc_C3 * Disc_C2 * Disc_C1,
        ISFILTERED ( 'Table'[Columns2] ) && ISFILTERED ( 'Table'[Columns1] ), Disc_C2 * Disc_C1,
        ISFILTERED ( 'Table'[Columns1] ), Disc_C1,
        ISFILTERED ( 'Table'[Columns3] )
            && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
                && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), Disc_C3,
        ISFILTERED ( 'Table'[Columns2] )
            && NOT ( ISFILTERED ( 'Table'[Columns3] ) )
                && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), Disc_C2
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Avg", [Sum] / Disc_ )
VAR Avg_ =
    AVERAGEX ( t2, [Avg] )
RETURN
    IF ( SUM ( 'Table'[Value] ) = Avg_, 0, 1 )
Measure_2 = 
SWITCH (
    TRUE (),
    ISFILTERED ( 'Table'[Columns3] ) && ISFILTERED ( 'Table'[Columns2] )
        && ISFILTERED ( 'Table'[Columns1] ),
        MAXX (
            ALLSELECTED ( 'Table'[Columns1], 'Table'[Columns2], 'Table'[Columns3] ),
            [Measure_1]
        ),
    ISFILTERED ( 'Table'[Columns2] ) && ISFILTERED ( 'Table'[Columns1] ), MAXX ( ALLSELECTED ( 'Table'[Columns1], 'Table'[Columns2] ), [Measure_1] ),
    ISFILTERED ( 'Table'[Columns1] ), MAXX ( ALLSELECTED ( 'Table'[Columns1] ), [Measure_1] ),
    ISFILTERED ( 'Table'[Columns3] )
        && NOT ( ISFILTERED ( 'Table'[Columns2] ) )
            && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), MAXX ( ALLSELECTED ( 'Table'[Columns3] ), [Measure_1] ),
    ISFILTERED ( 'Table'[Columns2] )
        && NOT ( ISFILTERED ( 'Table'[Columns3] ) )
            && NOT ( ISFILTERED ( 'Table'[Columns1] ) ), MAXX ( ALLSELECTED ( 'Table'[Columns2] ), [Measure_1] )
)

 

 

3. try it again. 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , there is nothing like a row-level operation in power bi. So you need to do it using a formula and color measure

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

For color measure

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-numbers-in-the-column
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.