# SWITCH in DAX with RELATED TABLE



## alt731 (Apr 9, 2018)

I'm in Power BI trying to add a calculated column.

I've got two tables, and a join between them: 1:n.

*Table 1:*

ID
Description
1
Bing
2
Bang
3
Bong


<tbody>

</tbody>
*Table 2:*

ID
Name
1
Joe
2
Fred


<tbody>

</tbody>
I can join them together like this:


ID
Description
ID
Name
1
Bing
1
Joe
2
Bang
2
Fred
3
Bong


<tbody>

</tbody>
As we can see, ID 3 in Table 1 does not have a corresponding ID in Table2

So what I am trying to do, is add a calculated column to using a SWITCH() function to get this:



ID
Description
ID
Name
SwitchColumn
1
Bing
1
Joe
Joe
2
Bang
2
Fred
Fred
3
Bong
Bong


<tbody>

</tbody>
Here is my code:

*SwitchColumn = SWITCH(RELATED('Table1'[ID]), BLANK(), 'Table2'[Name], 'Table1'[Description])*

However, its not working. What DAX code should I be using here? Thanks.


----------



## gazpage (Apr 11, 2018)

Why don't you do this in Power Query just after you do the merge?


----------



## alt731 (Apr 12, 2018)

gazpage said:


> Why don't you do this in Power Query just after you do the merge?



Thanks. There is no merge. I am joining the two tables together via a relationship in DAX. I guess the question is, is it possible to do what I want in DAX. I'm getting the impression that DAX can't cope with the type of logic I want, across tables.


----------

