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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
stribor45
Post Prodigy
Post Prodigy

Group by ID then filter based on multiple column

I am basically trying to filter rows based on this

  • group by ID
  • keep records where for this id Type 1 is "INT"
    • if for this id the Type 1 is not INT 
      • keep row where Type 2 is AF

This is what the date and result look like

 

IDScoreType 1Type 2
11111133INTNOCOMP
11111144NOTYPEAZ
11111155NOTYPEAZ
11111166NOTYPEAZ
11111177NOTYPEAZ
22222232NOTYPEAZ
22222272NOTYPEAF
    
IDScoreType 1Type 2
11111133INTNOCOMP
22222272NOTYPEAF

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

A little simpler:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQDJR0lY2Mg4ekXAiT9/J39fQOUYnWQpE1MwBIhkQGuQIZjFKqsqSk+WTMzfLLm5lhkjcAA5CwjfLLmqLJuSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Score = _t, #"Type 1" = _t, #"Type 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"ID", Int64.Type}, {"Score", Int64.Type}, {"Type 1", type text}, {"Type 2", type text}}),
   
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {
        {"all", each Table.SelectRows(_, each [Type 1]="INT" or [Type 2]="AF")  , 
        type table [ID=nullable number, Score=nullable number, Type 1=nullable text, Type 2=nullable text]}}),
   
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Score", "Type 1", "Type 2"})
in
    #"Expanded all"

 

ronrsnfld_0-1757024960156.png

 

 

View solution in original post

3 REPLIES 3
ronrsnfld
Super User
Super User

A little simpler:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQDJR0lY2Mg4ekXAiT9/J39fQOUYnWQpE1MwBIhkQGuQIZjFKqsqSk+WTMzfLLm5lhkjcAA5CwjfLLmqLJuSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Score = _t, #"Type 1" = _t, #"Type 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"ID", Int64.Type}, {"Score", Int64.Type}, {"Type 1", type text}, {"Type 2", type text}}),
   
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {
        {"all", each Table.SelectRows(_, each [Type 1]="INT" or [Type 2]="AF")  , 
        type table [ID=nullable number, Score=nullable number, Type 1=nullable text, Type 2=nullable text]}}),
   
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Score", "Type 1", "Type 2"})
in
    #"Expanded all"

 

ronrsnfld_0-1757024960156.png

 

 

jgeddes
Super User
Super User

Try this...

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQDJR0lY2Mg4ekXAiT9/J39fQOUYnWQpE1MwBIhkQGuQIZjFKqsqSk+WTMzfLLm5lhkjcAA5CwjfLLmqLJuSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Score = _t, #"Type 1" = _t, #"Type 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Score", Int64.Type}, {"Type 1", type text}, {"Type 2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"AllRows", each _, type table [ID=nullable number, Score=nullable number, Type 1=nullable text, Type 2=nullable text]}}),
    #"Select Nested Rows" = Table.TransformColumns(#"Grouped Rows", {{"AllRows", each Table.SelectRows(_, each if [Type 1] = "INT" then true else if [Type 2] = "AF" then true else false), type table [ID=nullable number, Score=nullable number, Type 1=nullable text, Type 2=nullable text]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Select Nested Rows", "AllRows", {"Score", "Type 1", "Type 2"}, {"Score", "Type 1", "Type 2"})
in
    #"Expanded AllRows"

Start...

jgeddes_0-1757012659169.png

End...

jgeddes_1-1757012681776.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





stribor45
Post Prodigy
Post Prodigy

stribor45_0-1757010962492.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.

Top Solution Authors
Users online (3,309)