Power Query multiple OR AND formula

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,144
Office Version
  1. 365
Platform
  1. Windows
Can someone help me with this.
as it stands the OR's are not working in the total formula correctly

ANY of the OR's must be TRUE
ALL of the AND's must be TRUE

Power Query:
if [Q1] = "A"
or [Q1] = "B"
or [Q1] = "C"

and [Q12] = "Replacement"
and [Q13] = "MyBrand"
and [Q14] = "Model x"

then "A replacement for x"
else "A replacement for y"
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hello,
I'm not familiar with this syntax, but what about this logic
Power Query:
if  [Q12] = "Replacement"
and [Q13] = "MyBrand"
and [Q14] = "Model x"
and (
  [Q1] = "A"
  or [Q1] = "B"
  or [Q1] = "C"
)
 
Upvote 1
Hi,

for example,

Power Query:
= Table.AddColumn(Source, "Answer", each if List.Contains({"A","B","C"}, [Q1]) and 
List.AllTrue({[Q12] = "Replacement", [Q13] = "MyBrand", [Q14] = "Model x"}) then "A replacement for x" else "A replacement for y")

Regards,
 
Upvote 0
Solution
Thank you that appears to work
 
Upvote 0
Great, That is the answer I was hoping for!
 
Upvote 0
With a function to easier M code maintenance:

Power Query:
fx_replace =
[
A = {{"Q12", "Q13", "Q14"}, {"Replacement", "MyBrand", "Model x"},"Q1", {"A","B","C"}, "Q1", {"A replacement for y", "A replacement for x"}},
B = (x)=> A{5}{Byte.From(List.AllTrue({List.Contains(A{3}, Record.Field(x,A{2})), Record.ToList(Record.SelectFields(x, A{0})) = A{1}}))}
] [B],
Result = Table.AddColumn(Source, "Answer", fx_replace)

Regards
 
Upvote 0

Forum statistics

Threads
1,226,267
Messages
6,189,940
Members
453,583
Latest member
Ok_category1816

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