我试图在Power BI中组合两个表。
我有以下两个表:
<table border="1">
<tr><th>Id</th><th>Category</th></tr>
<tr><td>1</td><td>A</td></tr>
<tr><td>1</td><td>B</td></tr>
<tr><td>2</td><td>A</td></tr>
<tr><td>3</td><td>B</td></tr>
<tr><td>3</td><td>C</td></tr>
<tr><td>4</td><td>A</td></tr>
</table>
<br>
<br>
<table border="1">
<tr><th>Id</th><th>Value</th></tr>
<tr><td>1</td><td>10</td></tr>
<tr><td>1</td><td>20</td></tr>
<tr><td>3</td><td>10</td></tr>
<tr><td>3</td><td>30</td></tr>
<tr><td>4</td><td>20</td></tr>
<tr><td>4</td><td>30</td></tr>
<tr><td>5</td><td>10</td></tr>
</table>
&#13;
我需要将它们组合如下:
<table border="1">
<tr><th>Id</th><th>Category</th><th>Value</th></tr>
<tr><td>1</td><td>A</td><th>10</th></tr>
<tr><td>1</td><td>A</td><th>20</th></tr>
<tr><td>1</td><td>B</td><th>10</th></tr>
<tr><td>1</td><td>B</td><th>20</th></tr>
<tr><td>2</td><td>A</td><th>BLANK</th></tr>
<tr><td>3</td><td>B</td><th>10</th></tr>
<tr><td>3</td><td>B</td><th>30</th></tr>
<tr><td>3</td><td>C</td><th>10</th></tr>
<tr><td>3</td><td>C</td><th>30</th></tr>
<tr><td>4</td><td>A</td><th>20</th></tr>
<tr><td>4</td><td>A</td><th>30</th></tr>
<tr><td>5</td><td>BLANK</td><th>10</th></tr>
</table>
&#13;
如何在Power BI中使用DAX实现这一目标?
答案 0 :(得分:1)
(Power Query,而不是DAX解决方案)
添加空白查询:
= Table.NestedJoin(Table1,{"Id"},Table2,{"Id"},"Table2",JoinKind.FullOuter)
添加转换步骤:
= Table.ExpandTableColumn(Source, "Table2", {"Id", "Value"}, {"Table2.Id", "Value"})
添加步骤:
= Table.AddColumn(#"Expanded Table2", "NewId", each (if [Id] = null then [Table2.Id] else [Id]))
删除列Id
和Table2.Id
。
或者,通过PowerBI Desktop进行GUI方法: