Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Dan-Smith
Frequent Visitor

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 of the same color then show as samecolor else show differentcolor. 
If any of the one item is of  different color then show differentcolor. 
how should I achieve this in power query ? 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Dan-Smith 

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

vxinruzhumsft_0-1700722586949.png

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.

 

View solution in original post

3 REPLIES 3
v-xinruzhu-msft
Community Support
Community Support

Hi @Dan-Smith 

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

vxinruzhumsft_0-1700722586949.png

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.

 

wdx223_Daniel
Super User
Super User

1 group your table by order id, and distinct count the item colors, if the count =1 then samecolor else differentcolor

2 merge above table with your original one to create a new column

Syndicate_Admin
Administrator
Administrator

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors