cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rogerbij Frequent Visitor
Frequent Visitor

Filter out row using Table.SelectRows and conditional if/and

Hi all, 

I need to drop a row from my table in power query (Excel). I presume I need to filter that row out. The trouble is that other rows also have than same value and I dont want to filter out the other ones too. For example, I want to filter out 

[Total]<>26 where in the same row the [Indicator] is "bob"

I do not want to filter out [Total]<>26 for "sally" and "jane"

I do not want to filter out "bob" if total does not equal 26 (since bob has other rows in other years I want to keep

 

I tried this

#"myfilter" = Table.SelectRows(#"previous step", each ([Total] <> 26 and [Indicator] <>"bob"))

But of course this filtered out all the 26 and all the bob entries...How do I write this please?

Best, Roger

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Filter out row using Table.SelectRows and conditional if/and

Hi @Rogerbij 

 

You can filter to Bob and 26 and add not like below.

 

= Table.SelectRows(#"Changed Type", each not ([Indicator] = "bob" and [Total] = 26))
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

Super User
Super User

Re: Filter out row using Table.SelectRows and conditional if/and

Hi @Rogerbij 

 

You can try the below.

 

= Table.SelectRows(#"Changed Type", 
        each not ( 
                ( [Indicator] = "bob" and [Total] = 26 ) 
             or ( [Indicator] = "jane" and [Total] = 21 )
             or ( [Indicator] = "jon" and [Total] = 15 )
        ) 
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Filter out row using Table.SelectRows and conditional if/and

Hi @Rogerbij 

 

You can filter to Bob and 26 and add not like below.

 

= Table.SelectRows(#"Changed Type", each not ([Indicator] = "bob" and [Total] = 26))
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

Rogerbij Frequent Visitor
Frequent Visitor

Re: Filter out row using Table.SelectRows and conditional if/and

Thanks a lot @Mariusz , 

each not() was exactly what I needed. 

I also figured I could add an Index column and then filter out that unique ID. 

Cheers, Roger

Rogerbij Frequent Visitor
Frequent Visitor

Re: Filter out row using Table.SelectRows and conditional if/and

Hi, can I ask a further question on this, 

 

How can I adjust the code so that this code:

= Table.SelectRows(#"Changed Type", each not ([Indicator] = "bob" and [Total] = 26))
= Table.SelectRows(#"Changed Type", each not ([Indicator] = "jane" and [Total] = 21))
= Table.SelectRows(#"Changed Type", each not ([Indicator] = "jon" and [Total] = 15))

is wrapped in something like a  

each [indicator]
each if then
else if then
else

So I dont have to keep writing '= Table.SelectRows(#' ? 

Thanks, Roger

Super User
Super User

Re: Filter out row using Table.SelectRows and conditional if/and

Hi @Rogerbij 

 

You can try the below.

 

= Table.SelectRows(#"Changed Type", 
        each not ( 
                ( [Indicator] = "bob" and [Total] = 26 ) 
             or ( [Indicator] = "jane" and [Total] = 21 )
             or ( [Indicator] = "jon" and [Total] = 15 )
        ) 
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

Rogerbij Frequent Visitor
Frequent Visitor

Re: Filter out row using Table.SelectRows and conditional if/and

Great, thanks! That simplifies my code a little 🙂

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 110 members 1,387 guests
Please welcome our newest community members: