Forum Discussion
VAR and SWITCH in Create New Column error
The nested IF statement is probably a good place to start - here's a more complex way to do it LINK but I wouldn't start with this approach.
Austin, the fnSwitch is a really nice learning exercise. I've not finished, it's a nice view forward into M's capabilities. I am going to do the Monkey thing and replicate it as a "pattern" piece of code and try it out....and then backfill my understanding of it. If I can get it to work, that would be a nice resource for my snippets collection.
Thanks,
Tom
- ThomasDay10 years agoImpactful Individual
One of the difficult things about M is figuring out where to enter code. I am creating connections only, using power bi, and loading the data model. When I'm building that query...I'll do a bunch of things, then want to use the switch function while creating a new column. (There's no intervening conversion of the column I'm assessing for the switch values.) Where do I put the code?
BTW, The DAX version is:
=
SWITCH (
TRUE(),
[CTRL_TYPE]= "1", "Nonprofit",
[CTRL_TYPE]= "2", "Nonprofit",
[CTRL_TYPE]= "3", "Nonprofit",
[CTRL_TYPE]= "4", "Proprietary",
[CTRL_TYPE]= "5", "Proprietery",
[CTRL_TYPE]= "6", "Proprietery",
[CTRL_TYPE]= "7", "Govt",
[CTRL_TYPE]= "8", "Govt",
[CTRL_TYPE]= "8", "Govt",
[CTRL_TYPE]= "9", "Govt",
[CTRL_TYPE]= "10", "Govt",
[CTRL_TYPE]= "11", "Govt",
[CTRL_TYPE]= "12", "Govt",
[CTRL_TYPE]= "13", "Govt",
"Undefined")