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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Collan
New Member

Validation of data against other rows PowerQuery

Hello All - hoping that someone can assist with guidance on M Code to achieve the Validation Result shown

 

The business scenario is that a set of manually entered input data needs to be validated before upload into an ITSM platform.

Columns A/B/C are data from the existing transformation steps & we need to create the Validation Result (Column D) as a new column (for further processing). Note that no rows can be removed during this validation.

DeviceSupport ContractClassValidation Result
Server1ContractAServerOK
Server1ContractBServerOK
Server2ContractAServerFail
Server2ContractCNetworkFail
Server3ContractAServerOK
Server4ContractBServerOK
Router1ContractCNetworkOK

 

A Device may have 1 or more Support Contracts assigned - these Contracts are used to define the associated Class of device.

When multiple Contracts are assigned to a specific Device, we need to check that each of associated Classes are the same (and mark both records as a Fail if the Class values are different)

We've already tried various GroupBy options but have been unable to find a workable result

Thank you in advance

 

1 ACCEPTED SOLUTION
Omid_Motamedise
Super User
Super User

Just copy and the below code and paste it into the Advance editor

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk4tKkstMlTSUXLOzyspSkwucQSyIaJKsTrYFDhhU2BEyARkBc5Atl9qSXl+UTaSCmNCRpjgdkRQfmkJqitR7IgFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Device = _t, #"Support Contract" = _t, Class = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Device", type text}, {"Support Contract", type text}, {"Class", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Device"}, {{"Count", each [a=_,b=List.Count(List.Distinct(a[Class])),c=Table.AddColumn(a,"Validation", (x)=> if b=1 then "Ok" else "Fail")][c]}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Device"}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Removed Columns", "Count", {"Device", "Support Contract", "Class", "Validation"}, {"Device", "Support Contract", "Class", "Validation"})
in
    #"Expanded Count"

 

If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. Thank you!

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

3 REPLIES 3
Omid_Motamedise
Super User
Super User

Just copy and the below code and paste it into the Advance editor

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk4tKkstMlTSUXLOzyspSkwucQSyIaJKsTrYFDhhU2BEyARkBc5Atl9qSXl+UTaSCmNCRpjgdkRQfmkJqitR7IgFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Device = _t, #"Support Contract" = _t, Class = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Device", type text}, {"Support Contract", type text}, {"Class", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Device"}, {{"Count", each [a=_,b=List.Count(List.Distinct(a[Class])),c=Table.AddColumn(a,"Validation", (x)=> if b=1 then "Ok" else "Fail")][c]}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Device"}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Removed Columns", "Count", {"Device", "Support Contract", "Class", "Validation"}, {"Device", "Support Contract", "Class", "Validation"})
in
    #"Expanded Count"

 

If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. Thank you!

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

Thank you so much Omid_Motamedise - it works purfectly! 

You are welcome

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors