从一个表动态比较行-DAX / M语言/ Power BI

时间:2018-09-18 06:35:54

标签: compare powerbi rows dax m

这可能吗?

我去了一张桌子,上面有产品的版本列-例如:快速车。 每个版本都有零件的列表-例如: colour 。 每个部分也都有一些:例如: red

VERSION PART PART_VALUE VERSION1 PART1 PART_VALUE1 VERSION1 PART2 PART_VALUE2 VERSION1 PART3 PART_VALUE3 VERSION2 PART2 PART_VALUE2 VERSION2 PART3 PART_VALUE3 VERSION2 PART4 PART_VALUE4 VERSION3 PART1 PART_VALUE1 VERSION3 PART2 PART_VALUE2 VERSION3 PART3 PART_VALUE4

现在我要在Fragmentator或其他复选框中进行选择: 版本1 版本2 ,结果我将拥有:

"ONLY DIFFENCES BETWEEN VERSION1 AND VERSION2"
VERSION1 PART1 PART_VALUE1 VERSION2 PART4 PART_VALUE4

或在选择 Version1 Version3 后,我将得到:

"ONLY DIFFENCES BETWEEN VERSION1 AND VERSION3"
VERSION1 PART3 PART_VALUE3 VERSION3 PART3 PART_VALUE4

1 个答案:

答案 0 :(得分:3)

这是一个M查询,它应该执行您想要的操作:

(V1, V2) =>
let
    Source = MyTable,
    First = Table.SelectRows(Source, each ([VERSION] = V1)),
    Second = Table.SelectRows(Source, each ([VERSION] = V2)),
    #"First Unique" = Table.NestedJoin(First,{"PART", "PART_VALUE"},Second,{"PART", "PART_VALUE"},"Second",JoinKind.LeftAnti),
    #"Second Unique" = Table.NestedJoin(Second,{"PART", "PART_VALUE"},First,{"PART", "PART_VALUE"},"First",JoinKind.LeftAnti),
    Combine = Table.Combine({#"First Unique", #"Second Unique"}),
    #"Removed Columns" = Table.RemoveColumns(Combine,{"Second", "First"})
in
    #"Removed Columns"