Home » excel » excel – Power BI – Assigning values in one column to a new value in a new calculated column

excel – Power BI – Assigning values in one column to a new value in a new calculated column

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a column that consists of a few different values and I want to assign each unique value to a new term in a new calculated column. I think the ‘if’ function is used but not too sure.

Here’s a mock up table of what I’m looking for – the ‘Year’ Column is what I would like to generate. table

enter image description here

How to&Answers:

Let’s say your table name is “MyTable”. Create a calculated column:

= SWITCH( 'MyTable'[Name],
           "A", 2019,
           "B", 2018,
           "C", 2017,
           "D", 2016)

You can also include a ‘catch all” choice if you want, for values not on the list:

= SWITCH( 'MyTable'[Name],
               "A", 2019,
               "B", 2018,
               "C", 2017,
               "D", 2016,
                0)

which will display 0 (or BLANK, or whatever) if you have a name other than A, B, C, D.

SWITCH function is just a compact form of IF, whenever you have more than 2 choices.