Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I'm looking for a way to create a new description field that translates a number to a name. For example, I want the value 1 (from Type field) to equal "Major" in a new (Description field) and 2 to equal "Minor" and so on. I believe DAX might get me there, but need a little assistance to get started. Thank you!
Solved! Go to Solution.
Hi @Anonymous The format of the SWITCH statement follows a pattern.
It goes, <test> and is then followed by pairs of IF/THEN which you can have as many as you like
but finally you need an <else> so please try this:
Column = SWITCH(Table[TypeID] ,
1 , "Major" ,
2 , "Minor" , "other" )
Hi @Anonymous
Sounds straight forward. If your table was called Table1 and the numeric column was called Status you could add a calcuated column to your table like this:
New Column = SWITCH('Table1'[Status] , 1 , "Major" , 2 , "Minor" , 3 , "and so on" , "Other" )
Give it a go and let us know how you get on
@Phil_Seamark Thanks for the tip! When I put that in, I get "Argument '6' in SWITCH function is required"
I put the following in:
Column = SWITCH(Table[TypeID] ,
1 , "Major" ,
2 , "Minor" , )
What am I missing here? Thanks!
Hi @Anonymous The format of the SWITCH statement follows a pattern.
It goes, <test> and is then followed by pairs of IF/THEN which you can have as many as you like
but finally you need an <else> so please try this:
Column = SWITCH(Table[TypeID] ,
1 , "Major" ,
2 , "Minor" , "other" )
@Phil_Seamark - Oddly enough, when I installed the March 2017 build of Power BI, it seems to have broken this statement! Now, it says that "A single value for column 'type' in table 'data' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result. Thoughts?
Hi @Anonymous,
I just tried it in the March version and it seems to be working. Are you definitely adding the code to a Calculated Column rather than a Measure?
You nailed it! Sorry, I didn't realize they weren't interchangeable I guess. Thanks for the quick response!
That did it! Really appreciate the help!
User | Count |
---|---|
128 | |
108 | |
99 | |
65 | |
62 |
User | Count |
---|---|
136 | |
113 | |
102 | |
71 | |
60 |