1+ // Readme
2+ let
3+ Source = "
4+ • The original question is from: <https://www.reddit.com/r/PowerBI/comments/1e26lk5/table_based_on_multiple_rows_joined_to_two/>
5+
6+ • 'Find Conflicts' is an expanded query that shows details
7+ you can visually inspect each stage of filtering
8+
9+ • 'Short Find Conflicts' is simplified. it does not show each individual step.
10+
11+
12+ "
13+ in
14+ Source
15+
16+ // User Perms
17+ let
18+ Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1OLXJU0lEKdnU2MjZSitVBETIxN0UXMrY0QRcyNDLG0IhplrkZQpUTpllOSGbFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Access = _t]),
19+ #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Access", type text}})
20+ in
21+ #"Changed Type"
22+
23+ // Conflicts
24+ let
25+ Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwsTQ1VtJRCnZ1NrY0gTAMjYyVYnWgklAxf39PLJKmaJLmpkiSZmiSBgYmCElziJiRsRGEYQJkxMYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, Source = _t, Destination = _t]),
26+ #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Source", type text}, {"Destination", type text}})
27+ in
28+ #"Changed Type"
29+
30+ // Find Conflicts
31+ let
32+ Source = #"User Perms",
33+ #"Removed Other Columns" = Table.SelectColumns(Source,{"User"}),
34+ #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
35+
36+ // I could have used the "Group" command.
37+ // I chose this to let you visualize each step along the way.
38+
39+ // grab all user values as a list
40+ #"AddCol Access List" = Table.AddColumn( #"Removed Duplicates", "Access List",
41+ (row) =>
42+ Table.SelectRows( Source, each [User] = row[User] )[Access]
43+ , Table.Type),
44+
45+ #"AddCol MatchesSource" = Table.AddColumn( #"AddCol Access List", "Matches First",
46+ (row) => Table.SelectRows( Conflicts,
47+ (perms) => List.Contains( row[Access List], perms[Source] ) )
48+ , Table.Type
49+ ),
50+ #"AddCol Found Conflicts" = Table.AddColumn( #"AddCol MatchesSource", "Found Conflicts",
51+ (row) => Table.SelectRows( row[Matches First],
52+ (perms) => List.Contains( row[Access List], perms[Destination] ) )
53+ , Table.Type
54+ ),
55+ #"Expanded Found Conflicts" = Table.ExpandTableColumn(#"AddCol Found Conflicts", "Found Conflicts", {"Id", "Source", "Destination"}, {"Conflict.Id", "Conflict.Source", "Conflict.Destination"}),
56+ #"Changed Type" = Table.TransformColumnTypes(#"Expanded Found Conflicts",{{"Conflict.Id", Int64.Type}, {"Conflict.Source", type text}, {"Conflict.Destination", type text}}),
57+ #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Access List", "Matches First"})
58+ in
59+ #"Removed Columns"
0 commit comments