Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Power Query find matching and non matching values

I have a orders table  each order has multiple items ordered . So one order can have 5 items ordered another can have 4. i have color column too in the table .  if all the items in the order are o...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous 

    You can put the following code to advanced editor in power query to as a reference.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSjRU0lECYfei1NQ8pVgdqJARppAxppAJppApilCSEYbxYCGo8ZUIEWMMERMMEVMMETO4SCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OrderId = _t, ItemID = _t, Color = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"OrderId", type text}, {"ItemID", Int64.Type}, {"Color", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"OrderId"}, {{"MinColor", each List.Min([Color]), type nullable text}, {"MaxColor", each List.Max([Color]), type nullable text}, {"Data", each _, type table [OrderId=nullable text, ItemID=nullable number, Color=nullable text]}}),
        #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"ItemID", "Color"}, {"ItemID", "Color"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Data", "Custom", each if [MinColor]=[MaxColor] then "same color" else " different color"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MinColor", "MaxColor"})
    in
        #"Removed Columns"

    Output

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.