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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.