Power Query/PowerBI 中的条件联接

问题描述 投票:0回答:1

我需要根据一个数据集中的值介于另一个数据集中的值之间来连接两个数据集。

数据集1(foo):

id 瓦尔
a 3
b 7
c 13

数据集 2(条):

描述 开始 终点
x 2 5
y 8 14
z 17 20

在 SQL 中,我会写:

select bar.descr
, bar.beginval
, bar.endval
, foo.id
from bar
  left outer join foo on foo.val between bar.beginval and bar.endval

这会产生:

描述 开始 终点 id
x 2 5 a
y 8 14 c
z 17 20 (空)

但是由于数据集并非来自同一来源,并且来源不一定是 SQL 数据库,因此我无法在 Power BI 中编写 SQL 来执行此操作。

在 Power BI 中,我发现我可以加入一列 = 一列。我没有看到加入范围的能力。这可以通过 DAX 或查询编辑器中的某种类型的操作实现吗?

powerbi powerquery data-manipulation powerbi-desktop m
1个回答
0
投票

在电源查询中:

答:

乙:

添加列并展开:

Table.SelectRows(B, (x)=> x[val] >= [beginval] and x[val] <= [endval])

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"descr", type text}, {"beginval", Int64.Type}, {"endval", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(B, (x)=> x[val] >= [beginval] and x[val] <= [endval])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"id"}, {"id"})
in
    #"Expanded Custom"
© www.soinside.com 2019 - 2024. All rights reserved.