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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Murali777
Helper III
Helper III

Compare two rows in different dataset to create flag measure column

Hi Superhero,

 

I'm having Name and country column (which is coming from two differnt tables), I want to create dynamic measure which same name having two differnt country then it should be 1 else 0. Please see my below data.

 

I need dynamic calculated measure.

 

Murali777_0-1650685158571.png

 

1 ACCEPTED SOLUTION

Hi @Murali777 ,

According to your description, I modify my sample, here's my solution.

Create a measure.

Measure_Flag =
VAR _T =
    CALCULATE (
        DISTINCTCOUNT ( Table2[Country] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Name] = MAX ( 'Table'[Name] ) )
    )
RETURN
    IF (
        _T > 1,
        1,
        IF (
            CALCULATE (
                MAX ( 'Table2'[Country] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Name] = MAX ( 'Table'[Name] ) )
            )
                = MAX ( 'Table2'[Country] ),
            0,
            BLANK ()
        )
    )

Get the expected result.

vkalyjmsft_0-1651198786476.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @Murali777 ,

According to your description, here's my solution.

Create a measure.

Measure_Flag =
VAR _T =
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Name] = MAX ( 'Table'[Name] )
                && 'Table'[Country] <> MAX ( 'Table'[Country] )
        )
    )
RETURN
    IF ( _T > 0, 1, 0 )

Get the expected result.

vkalyjmsft_0-1651136732767.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

HI Kalyj,

 

Thanks for your code. i'm getting the country coloumn from the different table. How can i use the second table in the above script ?

 

I have tried, but getting some error.

Hi @Murali777 ,

According to your description, I modify my sample, here's my solution.

Create a measure.

Measure_Flag =
VAR _T =
    CALCULATE (
        DISTINCTCOUNT ( Table2[Country] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Name] = MAX ( 'Table'[Name] ) )
    )
RETURN
    IF (
        _T > 1,
        1,
        IF (
            CALCULATE (
                MAX ( 'Table2'[Country] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Name] = MAX ( 'Table'[Name] ) )
            )
                = MAX ( 'Table2'[Country] ),
            0,
            BLANK ()
        )
    )

Get the expected result.

vkalyjmsft_0-1651198786476.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Thank you.. Its working fine.

Aburar_123
Resolver IV
Resolver IV

Hi @Murali777 ,

 

Please try the below calculated column,

 

Measure_Flag =

var _1 = calculate(countrows(<table_name>),filter(<table_name>,Name=earlier(Name))

return if(_1>1,1,0)

 

 

* Please Mark my post as a solution if it solves your Problem

Hi Aburar,

 

Thanks for your reply.. i want calculatd measure.. not calculated column.

 

Kindly help me for measure..

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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