简体   繁体   中英

Dynamic row comparison in one table - DAX / M language / Power BI

Is this possible?

I've got a table, with a column containing the version of product (for example: fast car ). Every version has a list of parts (for example: color ). Every part has a number of values (for example: 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

Now I want to select - in Fragmentator or in some other checkbox - Version1 and Version2 and the results should be:

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

or after selecting Version1 and Version3 the results should be:

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

Here's an M query which should do what you want:

(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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM