Forum Discussion
IF Multiple Columns equal to Value (Power Query M)
Hello, guys,
I need to know if there's a formula or function that lets me list columns and if those columns equal to a certain value on each row I want to return some value.
For example:
A B C D E RESULT
TRUE TRUE TRUE TRUE TRUE TRUE
TRUE FALSE TRUE FALSE FALSE FALSE
Normally, I would write:
if
[A] = true or
[B] = true or
[C] = true or
[D] = true
then true else false
But I have lot of columns and this is getting really messy, I'd like to see if there's a function for it, similar to List.Contains.
So ideally something like this:
if ColumnContains({"A","B","C","D"}, true) = true then true else false
And I want to do in Power Query M for each row.
Sorry for the formatting but it didn't allow me to use the table somehow.
You can use List.MatchesAny but what's the logic of the second line being equal to FALSE? If it follows the logic of the code you provided (each condition with an 'or'), it's TRUE
5 Replies
- HotChilliCommunity Champion
You can use List.MatchesAny but what's the logic of the second line being equal to FALSE? If it follows the logic of the code you provided (each condition with an 'or'), it's TRUE
- vojtechsimaSuper User
HotChilli ,
Yeah my bad, I didn'T really check the logic, it was just to give an example, that I need to check multiple columns. - vojtechsimaSuper User
HotChilli
So I used your logic and it's correct, thank you, HotChilli.List.MatchesAny({[A], [B], [C], [D]}, each _ = true)
- CNENFRNLCommunity Champion
= Table.AddColumn(#"Changed Type", "Result", each not List.Contains(Record.ToList(_),false))- vojtechsimaSuper User
CNENFRNL
Thank you for the effort, this checks if every column is the TRUE, right?
This doesn'T suit me, very well, in my real scenario but I agree, my example wasn't the best.
So thank you for the effort.