Forum Discussion
VAR and SWITCH in Create New Column error
Alright!! At least the DAX looks right. I'll take a look at M and see what might do the trick there since I would then never have to think about it again on data refresh. I'm guessing an intermediate col would be useful and then not load it....to break it into pieces.
Thanks again, and I'll try out the code above just for the satisfaction of it and then crack the M book. Tom
I really should ask: "do you have any tips for the approach in M?" Is it to create a temp column and build a big nested IF (presuming there is such a thing in M)? Thanks for any help in advance. Tom
- austinsense10 years agoImpactful Individual
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.
- ThomasDay10 years agoImpactful Individual
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")