Forum Discussion
Take maximum value from another table with duplicate values
- 5 years ago
Anonymous
Simple answer:
1. You didn't specify that
2. I didn't look in detail
Simplified version:
New column V2 = VAR auxT_ = CALCULATETABLE ( 'Reel defect', TREATAS ( CALCULATETABLE ( DISTINCT ( 'Reel status'[Key] ) ), 'Reel status'[Key] ) ) VAR maxLenT_ = TOPN ( 1, auxT_, [Length], DESC ) RETURN MAXX ( maxLenT_, [Fault code] )Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
Anonymous
If you need it in PQ (which you didn't specify at the beginning either), place the following M code in a blank query to see the steps:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdFBCoUwDIThu3StYDOJ6FnE+1/jKbwWZ5KFFORb/J1eV9v67m1p/f/ZuW/P8f5d+9rbvRCxREwJEoEST8SVRCLxJTZz4xzEONdm7peYEiQCJZ6IK4lEKBfFuuBcFOuCc1GsC85FsS44F8W64NzxCMcxhXPtuDcJUwEVUOEqXEWoeErvHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order = _t, #"Runup Sequence" = _t, Lane = _t, #"Reel Lenght" = _t, Key = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order", type text}, {"Runup Sequence", Int64.Type}, {"Lane", Int64.Type}, {"Reel Lenght", Int64.Type}, {"Key", type text}}), #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Key"}, #"Reel defect", {"Key"}, "Reel defect", JoinKind.LeftOuter), #"Added Custom" = Table.AddColumn(#"Merged Queries", "Fault code", (input)=> try let max_ = List.Max(input[Reel defect][Length]), pos_ = List.PositionOf(input[Reel defect][Length], max_, Occurrence.First), res_ = input[Reel defect][Fault code]{pos_} in res_ otherwise null, type text), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Reel defect"}) in #"Removed Columns"Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
Anonymous
See it all at work in the attached file.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi Anonymous
Please show both tables above in text-tabular format so that the contents can be copied. I'll then help with a PQ solution. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data). Show also the table with the final expect result for that data.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Reel status
Order Runup Sequence Lane Reel Length Key
0164 1 1 2960 0164-1-1
0164 1 2 2960 0164-1-2
0164 1 3 2960 0164-1-3
0164 1 4 2960 0164-1-4
0164 1 5 2960 0164-1-5
0164 2 1 2959 0164-2-1
0164 2 2 2959 0164-2-2
0164 2 3 2959 0164-2-3
0164 2 4 2959 0164-2-4
0164 2 5 2959 0164-2-5
0164 3 1 2960 0164-3-1
0164 3 2 2960 0164-3-2
0164 3 3 2960 0164-3-3
0164 3 4 2960 0164-3-4
0164 3 5 2960 0164-3-5
0164 4 1 880 0164-4-1
0164 4 2 880 0164-4-2
0164 4 3 880 0164-4-3
0164 4 4 880 0164-4-4
0164 4 5 880 0164-4-5
Reel defect
Order Runup Sequence Lane Fault Code Reason Code Length Reel Status Key
0164 1 1 100-07 1DA00 105 Doctor 0164-1-1
0164 1 1 100-07 1DA00 1 Doctor 0164-1-1
0164 1 3 212-04 30000 1 Doctor 0164-1-3
0164 3 3 316-10 30000 30 Doctor 0164-3-3
0164 3 3 212-04 30000 1 Doctor 0164-3-3
0164 5 4 590-01 5HA00 1 Doctor 0164-5-4