Is it possible to build a custom data quality rule that validates hierarchical relationships across two different tables?

Siddharth Chakraborty 20 Reputation points
2025-04-17T09:25:19.1233333+00:00

I am trying to write a rule saying if TableA_Field1 contains 'PlantABC', TableB_Field2 should contain either 'PlantA', 'PlantB' or 'PlantC' where TableA-->TableB has a one-many relationship. How can this be solved using Purview DQ?

Microsoft Purview
Microsoft Purview
A Microsoft data governance service that helps manage and govern on-premises, multicloud, and software-as-a-service data. Previously known as Azure Purview.
1,532 questions
0 comments No comments
{count} votes

Accepted answer
  1. Venkat Reddy Navari 1,270 Reputation points Microsoft External Staff
    2025-04-17T12:03:17.2566667+00:00

    Hi @Siddharth Chakraborty Yes, it's possible to create a custom data quality (DQ) rule in Microsoft Purview to validate hierarchical relationships across two different tables, though it requires a few workarounds since Purview’s out-of-the-box DQ capabilities are primarily column-level and table-level.

    In your scenario, since TableA → TableB has a one-to-many relationship and the rule depends on cross-table logic, you can approach it as follows:

    1. Use a Custom SQL Rule: If your data source supports it (like Azure SQL DB, Synapse, etc.), you can define a custom SQL query in your DQ rule that joins TableA and TableB based on the relationship and checks the logic. For example:
         SELECT B.*
         FROM TableA A
         JOIN TableB B ON A.Key = B.ForeignKey
         WHERE A.Field1 = 'PlantABC'
         AND B.Field2 NOT IN ('PlantA', 'PlantB', 'PlantC')
      
      This query identifies the records violating your logic. In Purview, you can configure a custom DQ rule with this logic and define it as a "Row-level" validation.
    2. Custom Rule in DQ Rule Set: Go to the Data Map → Rules → Add Rule Set → Custom Rule → SQL Rule (or Spark rule if using a Spark-based scan). Include the logic above and assign it to the dataset.
    3. Validation: After applying the rule, run a scan with DQ enabled to evaluate the quality. The DQ results will show how many records pass/fail the rule.

    I hope this information helps. Please do let us know if you have any further queries.

    Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.