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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dmoresco
Regular Visitor

How to remove items from a list if contained in another list

I have one column which is a list of items. I have a second column which is an exclusion list. I want to create a third column (or modify the first) to remove any item present in the second column. Please see example below. Thanks in advance for any help.

 

Column 1Column 2Result
X,M,J,ZZX,M,J
B,C,V B,C,V
C,D,F,GF,GC,D
2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

@dmoresco 

 

Using M/QueryEditor/Power Query...you can use this custom column

 

=Text.Combine(
List.RemoveItems
(Text.Split([Column 1],","),Text.Split([Column 2],","))
,
",")

View solution in original post

Zubair_Muhammad
Community Champion
Community Champion

@dmoresco 

 

As a DAX calculated column you can use.

 

Please see attached file with both ways

 

Calculated Column =
VAR List1 =
    SUBSTITUTE ( [Column 1], ",", "|" )
VAR T1 =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( List1 ) ),
            "Item", PATHITEM ( List1, [Value], TEXT )
        ),
        "Item", [Item]
    )
VAR List2 =
    SUBSTITUTE ( [Column 2], ",", "|" )
VAR T2 =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( List2 ) ),
            "Item", PATHITEM ( List2, [Value], TEXT )
        ),
        "Item", [Item]
    )
RETURN
    CONCATENATEX ( EXCEPT ( T1, T2 ), [Item], "," )

vbcvb.png

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@dmoresco 

 

As a DAX calculated column you can use.

 

Please see attached file with both ways

 

Calculated Column =
VAR List1 =
    SUBSTITUTE ( [Column 1], ",", "|" )
VAR T1 =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( List1 ) ),
            "Item", PATHITEM ( List1, [Value], TEXT )
        ),
        "Item", [Item]
    )
VAR List2 =
    SUBSTITUTE ( [Column 2], ",", "|" )
VAR T2 =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( List2 ) ),
            "Item", PATHITEM ( List2, [Value], TEXT )
        ),
        "Item", [Item]
    )
RETURN
    CONCATENATEX ( EXCEPT ( T1, T2 ), [Item], "," )

vbcvb.png

Zubair_Muhammad
Community Champion
Community Champion

@dmoresco 

 

Using M/QueryEditor/Power Query...you can use this custom column

 

=Text.Combine(
List.RemoveItems
(Text.Split([Column 1],","),Text.Split([Column 2],","))
,
",")

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!

December 2024

A Year in Review - December 2024

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