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.
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.