Forum Discussion
Switch statement in power query
- Anonymous5 years ago
the code you indicate I believe is DAX (which I don't know). Try to see if this is okay for you. If the control conditions are different (not "simple" equalities) it is necessary to change the setting. But in case you should give specific examples of which situation you need to manage.
- 5 years ago
Hi Anonymous
There is no built-in Switch function in Power Query. In additon to the custom Switch function, you can also achieve this by adding a conditional column easily. It will generate an IF statement like below.
if [Segment1] = 1 then "ABC" else if [Segment1] = 54 then "FGH" else if [Segment1] = 56 then "JKL" else if [Segment1] = 101 then "BNM" else nullRegards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
waiting for you to better clarify what you expect, I propose this scheme.
let
/* switch( c )
{
case 'A':
capital_a++;
case 'a':
letter_a++;
default :
total++;
}
*/
switch= (c) =>
if c= "A" then "add_One_A" else
if c="a" then "add_One_a" else
"add_nOne_a"
in
switch
- Anonymous5 years agoNot applicableSWITCH (TRUE (),'Discoverer-Receivables'[Segment1] = 1, "ABC",'Discoverer-Receivables'[Segment1] = 54, "FGH",'Discoverer-Receivables'[Segment1] = 56, "JKL",'Discoverer-Receivables'[Segment1] = 101, "BNM")Looking to implement this logic in power query
- v-jingzhang5 years agoCommunity Support
Hi Anonymous
There is no built-in Switch function in Power Query. In additon to the custom Switch function, you can also achieve this by adding a conditional column easily. It will generate an IF statement like below.
if [Segment1] = 1 then "ABC" else if [Segment1] = 54 then "FGH" else if [Segment1] = 56 then "JKL" else if [Segment1] = 101 then "BNM" else nullRegards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.- dhickey2 years agoNew Member
Well that just made my life a whole lot easier! Thank you!
- Anonymous5 years agoNot applicable
the code you indicate I believe is DAX (which I don't know). Try to see if this is okay for you. If the control conditions are different (not "simple" equalities) it is necessary to change the setting. But in case you should give specific examples of which situation you need to manage.