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
kevincoleman
New Member

How to Filter Rows by Correlating Values in One Column to Another

Example:

BEFORE

AAAEggs0
AAAMilk1
BBBCookies0
BBBEggs0
CCCMilk1
CCCEggs1

 

 

AFTER

CCCMilk1
CCCEggs1

 

 

Goal: FOR each row with the value '0' in column 3, FILTER out all rows that have the same value in column 1.

(Since Row 1 had a 0 in column 3, all rows with 'AAA' in column 1 were filtered out.) 

(Since Row 2 had a 0 in column 3, all rows with 'BBB' in column 1 were filtered out.)

 

How can I acheive this using M ?

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @kevincoleman 

Please see the M script below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0VNJRck1PLwZSBkqxOjAh38ycbCBlCBZycnICsp3z87MzUxEKIaIoep2dndH1QoSgqoBCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column3] = 0)),
    #"Exclude List" = List.Distinct(Table.Column(#"Filtered Rows","Column1")),
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each List.Contains(#"Exclude List", [Column1]) = false)
in
    #"Filtered Rows1"


Regards,
Mariusz

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

2 REPLIES 2
Mariusz
Community Champion
Community Champion

Hi @kevincoleman 

Please see the M script below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0VNJRck1PLwZSBkqxOjAh38ycbCBlCBZycnICsp3z87MzUxEKIaIoep2dndH1QoSgqoBCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column3] = 0)),
    #"Exclude List" = List.Distinct(Table.Column(#"Filtered Rows","Column1")),
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each List.Contains(#"Exclude List", [Column1]) = false)
in
    #"Filtered Rows1"


Regards,
Mariusz

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

Or you could do this in a measure. The following measure will return 1 for rows which don't have a 0 against the item in Column1 so you can just add filter to your visual for where this measure is 1.

 

Measure = 
VAR col1WithZero = CALCULATETABLE(DISTINCT(Table1[Column1]),  FILTER(ALL(Table1), table1[Column3] = 0))
var result = COUNTROWS(FILTER(VALUES(Table1[Column1]), NOT Table1[Column1] IN col1WithZero))
return result

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.