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
adelmonte
Resolver I
Resolver I

Multiple columns comparison with a measure or calculated column.

Hi all,

 

I need to compare multiple pair of columns.

Desired Outcome in Yelow:

Comparison.png

 

I tried to create 1 Conditional Column in power query with multiple IFs, but it doesn't work.
Instead of creating multiple comparison columns, is there a way to have only one measure or calculated column that checks all conditions and returns a correct value.

Thanks in advance.
Alex

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @adelmonte ,

 

Currently you want to compare multiple pairs of columns in one table. Your logic is if Colum1[Value] = Colum2[Value] then True else False. However Power Query, Dax only support you to compare determind columns instead of dynamic columns. So you need to determind column1 and column2 in your code. Only one measure couldn't compair all pairs of columns. 

Here I suggest you to add an Index column in your table then use unpivot function to transform your table.

After transformation, my Sample looks like as below.

1.png

Create a measure.

Compare pair of columns = 
VAR _ADD =
    ADDCOLUMNS (
        ALL ( 'Table' ),
        "Left", LEFT ( [Column Header], 2 ),
        "Right", RIGHT ( [Column Header], 2 )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _ADD,
        "01",
            IF (
                [Right] = "02",
                MAXX (
                    FILTER (
                        _ADD,
                        [Index] = EARLIER ( [Index] )
                            && [left] = EARLIER ( [Left] )
                            && [Right] = "01"
                    ),
                    [Value]
                ),
                BLANK ()
            )
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD1,
        "TRUE/FALSE",
            IF ( [Right] = "02", IF ( [Value] = [01], "True", "False" ), BLANK () )
    )
RETURN
    MAXX (
        FILTER (
            _ADD2,
            [Index] = SUM ( 'Table'[Index] )
                && [Column Header] = MAX ( 'Table'[Column Header] )
        ),
        [TRUE/FALSE]
    )

Create a matrix visual. We only need measure result next column02, so turn off word wrap in Format and reduce the width of measure result for column01 to 0. Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @adelmonte ,

 

Currently you want to compare multiple pairs of columns in one table. Your logic is if Colum1[Value] = Colum2[Value] then True else False. However Power Query, Dax only support you to compare determind columns instead of dynamic columns. So you need to determind column1 and column2 in your code. Only one measure couldn't compair all pairs of columns. 

Here I suggest you to add an Index column in your table then use unpivot function to transform your table.

After transformation, my Sample looks like as below.

1.png

Create a measure.

Compare pair of columns = 
VAR _ADD =
    ADDCOLUMNS (
        ALL ( 'Table' ),
        "Left", LEFT ( [Column Header], 2 ),
        "Right", RIGHT ( [Column Header], 2 )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _ADD,
        "01",
            IF (
                [Right] = "02",
                MAXX (
                    FILTER (
                        _ADD,
                        [Index] = EARLIER ( [Index] )
                            && [left] = EARLIER ( [Left] )
                            && [Right] = "01"
                    ),
                    [Value]
                ),
                BLANK ()
            )
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD1,
        "TRUE/FALSE",
            IF ( [Right] = "02", IF ( [Value] = [01], "True", "False" ), BLANK () )
    )
RETURN
    MAXX (
        FILTER (
            _ADD2,
            [Index] = SUM ( 'Table'[Index] )
                && [Column Header] = MAX ( 'Table'[Column Header] )
        ),
        [TRUE/FALSE]
    )

Create a matrix visual. We only need measure result next column02, so turn off word wrap in Format and reduce the width of measure result for column01 to 0. Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

Thank you very much RicoZhou

amitchandak
Super User
Super User

@adelmonte , You can create a color measure and use that in conditional formatting. It can be as complex as you want, as long as it works

 

example

color =
switch ( true(),
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity1" && sum('Table'[Value]) >500,"lightgreen",
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity2" && sum('Table'[Value]) >1000,"lightgreen",
// Add more conditions
"red"
)

 

Arrow color =
var _change =[Net Sales YTD]-[Net Sales LYTD]
return
SWITCH (
TRUE(),
_change > 0, "green",
_change = 0, "blue",
_change < 0, "red"
)

 

 

How to do conditional formatting by measure and apply it on pie?: https://youtu.be/RqBb5eBf_I4

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

Amit please read well post and don't spam post if you don't have a solution

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.