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

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

Reply
Anonymous
Not applicable

Power Query Filter column on other column

Hi all,

 

is there a way to filter a query on a column, based on the value of another column in PowerQuery?

 

In my case, I would like to remove a series if it contains any Nan.

 

Here's an example of the input:

ace4_0-1661962371124.png

and the desired result:

ace4_1-1661962435746.png

 

 

I have tried with workaround, like filtering a custom column that sums up all the elements according to their value in column 1 (like a sumif in excel), but the dataset is too heavy, and this results to be very very slow...

 

#"Aggiunta colonna personalizzata2" = Table.AddColumn(#"Rimosse colonne", "Custom Column", each let _item = [Column 1] in
        List.Sum(
            Table.SelectRows(#"Rimosse colonne", each [Column 1] = _item)[Column 2])),
    #"Filtrate righe" = Table.SelectRows(#"Aggiunta colonna personalizzata2", each (not Number.IsNaN([Custom Column])))

 

 

Is there a simpler way?

 

thanks!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous you can try this, use group by and then call a function to flag

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTKxVIrVgTCNzOFMMCMJyDA1hTPNzOFMCwgzGaYShWEGMTEFZLgJnAk1HMQ0U4qNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"ALL", each _, type table [Column1=nullable text, Column2=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each fnFlag([ALL])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column2", "Exclude"}, {"Column2", "Exclude"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Exclude] = "No")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"ALL", "Exclude"})
in
    #"Removed Columns"

 

code for the fnFlag function:

 

(tbl as table) =>
let
    Source = tbl,
    FilterNull = Table.SelectRows(Source, each [Column2] = null),
    RowsCount = Table.RowCount(FilterNull),
    AddFlag = Table.AddColumn(Source, "Exclude", each if RowsCount >= 1 then "Yes" else "No")
    
in
    AddFlag

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@Anonymous glad it worked out. Yes, I was not sure about the actual data so just used Null.

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous did the provided solution work?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

yes!

Thanks a lot

parry2k
Super User
Super User

@Anonymous you can try this, use group by and then call a function to flag

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTKxVIrVgTCNzOFMMCMJyDA1hTPNzOFMCwgzGaYShWEGMTEFZLgJnAk1HMQ0U4qNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"ALL", each _, type table [Column1=nullable text, Column2=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each fnFlag([ALL])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column2", "Exclude"}, {"Column2", "Exclude"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Exclude] = "No")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"ALL", "Exclude"})
in
    #"Removed Columns"

 

code for the fnFlag function:

 

(tbl as table) =>
let
    Source = tbl,
    FilterNull = Table.SelectRows(Source, each [Column2] = null),
    RowsCount = Table.RowCount(FilterNull),
    AddFlag = Table.AddColumn(Source, "Exclude", each if RowsCount >= 1 then "Yes" else "No")
    
in
    AddFlag

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Great!

 

it worked perfectly, thanks a lot!

I just had to change the condition in the fnFlag function

 

FilterNull = Table.SelectRows(Source, each (Number.IsNaN([value])))

  

parry2k
Super User
Super User

@Anonymous what is the logic to filter? if any id has nan then filter that id?

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

yes, that was exactly the logic, thanks!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.