0
votes

Im working towards creating a calculated column that should contain an integer value specified by me if the criteria is met. So, from a single table, I want to check values of few columns, if the values that i specify are present in those column then the custom column should return an integer value specified by me. For example

Column A, Column B, Column C

arizona, 3, 3109
colorado,4, 2353
.
.
.
california,23, 6978

I want to create a custom column in such a way that if column a='california' && column b='3' && column c= '3109' then 7 elseif column a='california' && column b='5' && column c='3109' then 8 elseif and so on.

I have tried all the possible functions in PowerBi but it is not giving the desired output.

any kind of lead will be appreciated.

Thanks

1

1 Answers

0
votes

Best way to do this is in the query editor. Go to Edit Queries > Add Column > Custom Column and use following code:

= if [Column A] = "california" and [Column B] = "3" and [Column C] = "3109" then 7 
  else if [Column A] = "california" and [Column B] = "5" and [Column C] = "3109" then 8
  else if ...more conditions...
  else 0      ' <- This one is for the case that no if condition is met and closes the if

Note that if Column B and Column C of type numberic you have to write it without the quotes. Like this:

 = if [Column A] = "california" and [Column B] = 3 and [Column C] = 3109 ...