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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jose_cruzrodz
New Member

Filter records by second column, based on primary column answer

Greetings,

 

Here is my sample data:

Screenshot 2023-08-16 100052.jpg

 

Expected result:

Screenshot 2023-08-16 103154.jpg

 

 

 

 

 

 

What I need to accomplish is look at Column E first. If that column has a value of "Yes", then I look at Column B of that same record/row and grab its value. Once I get the target value of Column B, I will filter the table to show only all rows/records that match that collected value of Column B. From my example table, rows 6 and 10 had "Yes" as an answer in Column E, so, I grabbed their related values of Column B ("456" and "789", respectivaly). With those values at hand, I set my filter in Column B to just show all records that match those values. Column E is used to identify the target value of Column B, the filter itself is in Column B. All this must be done in POWER QUERY.

 

I have played with Custom Columns or Advanced Filters, but I cannot get it to work. Can someone help me with achieving what I need?

 

 

Thanks,

José

1 ACCEPTED SOLUTION
Syk
Super User
Super User

First thing that comes to my head is this..
Duplicate the Table and remove all but columns B and E and filter it to just "Yes"

Syk_0-1692208086495.png

Then, merge this table back to your main table using column B

Syk_1-1692208136285.png

Expand column E(from table 2) and rename it to make it a little more clear.
Use this new column and only filter for "Yes"

Syk_2-1692208203265.png

 

 

View solution in original post

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

Insert this code where #"Changed Type" should be replaced with your previous step

= Table.Combine(List.Select(Table.Group(#"Changed Type", {"ColumnB"}, {{"All", each _}})[All], (x)=>List.Contains(x[ColumnE], "Yes")))

Complete test code in action for testing

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk8sSS1S0lEyNDIGksGlxYl5QDo7JSs7BUgrxeoglJiYmoGUlKSWpQLptNTUwtRCmJrgxLwUAkoIGBOZWoyizNzCEkg65iWCFKWkpaDZhCqdkoZkQmJeZUlGZl46LkNiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t, ColumnB = _t, ColumnC = _t, ColumnD = _t, ColumnE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ColumnA", type text}, {"ColumnB", Int64.Type}, {"ColumnC", type text}, {"ColumnD", type text}, {"ColumnE", type text}}),
    #"Grouped Rows" = Table.Combine(List.Select(Table.Group(#"Changed Type", {"ColumnB"}, {{"All", each _}})[All], (x)=>List.Contains(x[ColumnE], "Yes")))
in
    #"Grouped Rows"
Syk
Super User
Super User

First thing that comes to my head is this..
Duplicate the Table and remove all but columns B and E and filter it to just "Yes"

Syk_0-1692208086495.png

Then, merge this table back to your main table using column B

Syk_1-1692208136285.png

Expand column E(from table 2) and rename it to make it a little more clear.
Use this new column and only filter for "Yes"

Syk_2-1692208203265.png

 

 

It is definitely not the best solution in terms of performance and data duplication (on the Power Query side), but it certainly worked and achieved what I needed! Right now, the raw data is about 5K records so I can live with this for now. At least I can generate the preliminary report while I find the permanent solution. You are definitely a life saver! I absolutely appretiate your help. Thanks a lot!!!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors