SWITCH in DAX with RELATED TABLE

alt731

New Member
Joined
Jun 28, 2017
Messages
3
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:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Description
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Bing
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Bang
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Bong
[/TD]
[/TR]
</tbody>[/TABLE]

Table 2:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Name
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Joe
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Fred
[/TD]
[/TR]
</tbody>[/TABLE]

I can join them together like this:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Description
[/TD]
[TD]ID
[/TD]
[TD]Name
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Bing
[/TD]
[TD]1
[/TD]
[TD]Joe
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Bang
[/TD]
[TD]2
[/TD]
[TD]Fred
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Bong
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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:


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Description
[/TD]
[TD]ID
[/TD]
[TD]Name
[/TD]
[TD]SwitchColumn
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Bing
[/TD]
[TD]1
[/TD]
[TD]Joe
[/TD]
[TD]Joe
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]Bang
[/TD]
[TD]2
[/TD]
[TD]Fred
[/TD]
[TD]Fred
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]Bong
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Bong
[/TD]
[/TR]
</tbody>[/TABLE]

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.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top