Two If Not Conditions in Power Query

LtCmdrData

Board Regular
Joined
Jan 24, 2018
Messages
58
Office Version
  1. 365
Platform
  1. Windows
In Power Query I am trying to check two different zip code columns for certain conditions. I want to check each column to see if they contain one of four zip codes. If either column contains any of the four zip codes, then I want one result but if neither column contains any of the four, I want a different result returned. Here is a sample of the M code I tried:

if [Origin Zip] <> "37167" or [Origin Zip] <> "43228" or [Origin Zip] <> "76118" or [Origin Zip] <> "92518"
and [Dest Zip] <> "37167" or [Dest Zip] <> "43228" or [Dest Zip] <> "76118" or [Dest Zip] <> "92518"
then "DS"

else "RS"

Perhaps I need to go about this a different way but I am stuck, probably because of the two negative conditions. Can anyone please help? Thank you in advance.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I would change the <> to = and go about it from that perspective so that you are looking for positive results versus negative results.
 
Upvote 0
Try

Power Query:
if List.AllTrue(
                   {
                      List.Contains({"37167" ,"43228","76118", "92518" },  [Origin Zip] )
                    , List.Contains({"37167" ,"43228","76118", "92518" },  [Dest Zip] )
                   }
                 )
then "DS"
else "RS"

If the ZIP codes are numerical, the quotation marks wrapping the codes are not required.
 
Upvote 0
I would change the <> to = and go about it from that perspective so that you are looking for positive results versus negative results.
Thank you for your reply. I wish I could use the positive but then I would have to include so many other possibilities they would be too numerous to list.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Excel Forum
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Try

Power Query:
if List.AllTrue(
                   {
                      List.Contains({"37167" ,"43228","76118", "92518" },  [Origin Zip] )
                    , List.Contains({"37167" ,"43228","76118", "92518" },  [Dest Zip] )
                   }
                 )
then "DS"
else "RS"

If the ZIP codes are numerical, the quotation marks wrapping the codes are not required.
 
Upvote 0
When I try this code suggestion, it is not excluding those origin zips listed.
 
Upvote 0
Then try if not... But same code after that, or inverse the true/false part.
 
Upvote 0
I think what you want is:

Power Query:
if List.AnyTrue(
                   {
                      List.Contains({"37167" ,"43228","76118", "92518" },  [Origin Zip] )
                    , List.Contains({"37167" ,"43228","76118", "92518" },  [Dest Zip] )
                   }
                 )
then "RS"
else "DS"
 
Upvote 0
When I tried List.AnyTrue it gives me rows that contain one of the listed zip codes. I'm looking for a solution that will exclude all the listed zip codes. Changing the if to if not didn't work either for some reason.
 
Upvote 0

Forum statistics

Threads
1,215,126
Messages
6,123,198
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top