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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KipGum
Microsoft Employee
Microsoft Employee

Comparing two different columns based on a third column

Hi all,

 

I have the following table:

 

UpdateLevel1     DomainAndSam    AffectedObject

 

Level1                 contoso\User1       contoso\Group1

Level1                 contoso\Group9    contoso\Group10

<Blank>             contoso\User2        contoso\Group2

<Blank>             contoso\Group1     contoso\Group3

<Blank>             contoso\Group10   contoso\Group11

 

I need to create a new column called UpdateLevel2 = "Level2" if the DomainAndSam column matches the AffectedObject of any of the records that have UpdateLevel1="Level1".  From the example above, the output should look like this:

 

UpdateLevel1     DomainAndSam    AffectedObject        UpdateLevel2

 

Level1                 contoso\User1       contoso\Group1       <Blank>

Level1                 contoso\Group9    contoso\Group10     <Blank>

<Blank>             contoso\User2        contoso\Group2      <Blank>

<Blank>             contoso\Group1     contoso\Group3       Level2

<Blank>             contoso\Group10   contoso\Group11     Level2

 

The UpdateLevel1 column is calculated as a measure.

 

Any help would be greatly appreciated!

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

Hi @KipGum ,

 

Please follow these steps:

(1) Create a new measure to select Level1

 

UpdateLevel1 = 
IF (
    ISFILTERED ( 'PrivilegedAccounts'[DomainAndSam] ),
    IF (
        MAX( 'PrivilegedAccounts2'[DomainAndSam] )
            IN VALUES ( PrivilegedAccounts[DomainAndSam] ),
        "Level1"
    )
)

 

(2) Create a new measure to select Level2

 

UpdateLevel2 =
VAR _in =
    SUMMARIZE (
        FILTER (
            ALL ( 'PrivilegedAccounts2' ),
            [DomainAndSam] IN VALUES ( PrivilegedAccounts[DomainAndSam] )
        ),
        [AffectedObject]
    )
RETURN
    IF (
        ISFILTERED ( 'PrivilegedAccounts'[DomainAndSam] ),
        IF ( MAX ( 'PrivilegedAccounts2'[DomainAndSam] ) IN _in, "Level 2" )
    )

 


(3)
The end result

vjialluomsft_2-1667958279558.png

 

vjialluomsft_3-1667958279560.png

 

Best Regards,

Gallen Luo

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-jialluo-msft
Community Support
Community Support

Hi @KipGum ,

 

Please follow these steps:

(1) Create a new measure to select Level1

 

UpdateLevel1 = 
IF (
    ISFILTERED ( 'PrivilegedAccounts'[DomainAndSam] ),
    IF (
        MAX( 'PrivilegedAccounts2'[DomainAndSam] )
            IN VALUES ( PrivilegedAccounts[DomainAndSam] ),
        "Level1"
    )
)

 

(2) Create a new measure to select Level2

 

UpdateLevel2 =
VAR _in =
    SUMMARIZE (
        FILTER (
            ALL ( 'PrivilegedAccounts2' ),
            [DomainAndSam] IN VALUES ( PrivilegedAccounts[DomainAndSam] )
        ),
        [AffectedObject]
    )
RETURN
    IF (
        ISFILTERED ( 'PrivilegedAccounts'[DomainAndSam] ),
        IF ( MAX ( 'PrivilegedAccounts2'[DomainAndSam] ) IN _in, "Level 2" )
    )

 


(3)
The end result

vjialluomsft_2-1667958279558.png

 

vjialluomsft_3-1667958279560.png

 

Best Regards,

Gallen Luo

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

tamerj1
Super User
Super User

Hi @KipGum 
Please try

UpdateLevel2 =
VAR CurrentLevel1 = [UpdateLevel1]
VAR CurrentDomain =
    SELECTEDVALUE ( 'Table'[DomainAndSam] )
VAR T1 =
    CALCULATETABLE (
        SUMMARIZE ( 'Table', 'Table'[DomainAndSam], 'Table'[AffectedObject] ),
        ALLSELECTED ( 'Table' )
    )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@Level1",
            VAR DomainSam = 'Table'[DomainAndSam]
            VAR AffectedObject = 'Table'[AffectedObject]
            RETURN
                CALCULATE (
                    [UpdateLevel1],
                    ALL ( 'Table' ),
                    'Table'[DomainAndSam] = Domain,
                    'Table'[AffectedObject] = AffectedObject
                )
    )
VAR T3 =
    FILTER ( T2, [@Level1] <> BLANK () )
VAR T4 =
    SELECTCOLUMNS ( T3, "@Object", [AffectedObject] )
RETURN
    IF ( ISBLANK ( CurrentLevel1 ), IF ( CurrentDomain IN T4, "Level2" ) )
KipGum
Microsoft Employee
Microsoft Employee

I just tested this but it's returning only blanks.  My table name is "PrivilegedAccounts2".  I'm guessing that the line that reads:

 

'Table'[DomainAndSam] = Domain,

 was meant to read:

'Table'[DomainAndSam] = DomainSam,

 

Here's the code as I am testing it:

 

UpdateLevel2 =
VAR CurrentLevel1 = [UpdateLevel1]
VAR CurrentDomain =
    SELECTEDVALUE ( 'PrivilegedAccounts2'[DomainAndSam] )
VAR T1 =
    CALCULATETABLE (
        SUMMARIZE ( 'PrivilegedAccounts2', 'PrivilegedAccounts2'[DomainAndSam], 'PrivilegedAccounts2'[AffectedObject] ),
        ALLSELECTED ( 'PrivilegedAccounts2' )
    )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@Level1",
            VAR DomainSam = 'PrivilegedAccounts2'[DomainAndSam]
            VAR AffectedObject = 'PrivilegedAccounts2'[AffectedObject]
            RETURN
                CALCULATE (
                    [UpdateLevel1],
                    ALL ( 'PrivilegedAccounts2' ),
                    'PrivilegedAccounts2'[DomainAndSam] = DomainSam,
                    'PrivilegedAccounts2'[AffectedObject] = AffectedObject
                )
    )
VAR T3 =
    FILTER ( T2, [@Level1] <> BLANK () )
VAR T4 =
    SELECTCOLUMNS ( T3, "@Object", [AffectedObject] )
RETURN
     IF ( ISBLANK ( CurrentLevel1 ), IF ( CurrentDomain IN T4, "Level2" ) )
 
 
Have any ideas?

@KipGum 

What do you have in the table visual? Any other table involved? I assumed only UpdateLevel1 is measure, the other two are columns?

KipGum
Microsoft Employee
Microsoft Employee

I have another table called "PrivilegedAccounts" which has the exact same columns as "PrivlegedAccounts2".  I have a slicer for DomainAndSam on "PrivilegedAccounts".  I have the following Measure in "PrivilegedAccounts2" that populates "UpdateLevel1" with the selected DomainAndSam value from "PrivilegeAccounts":

 

UpdateLevel1 = VAR sele = SELECTEDVALUE(PrivilegedAccounts[DomainAndSam]) RETURN IF(ISFILTERED(PrivilegedAccounts[DomainAndSam]) && MAX(PrivilegedAccounts2[DomainAndSam]) = sele,"Level1","")
 
KipGum
Microsoft Employee
Microsoft Employee

@tamerj1 

Do you think there is a solution to this?  Or do you think my use of UpdateLevel1 is flawed?

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.