Consistency Rules
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
Rule Name: Customer_Address_Consistency
Description: Validates customer addresses reference valid address records
Data Quality Dimension: Consistency
Schedule: Daily
Target: Sales.CustomerSELECT
COUNT(*) AS total_count,
SUM(CASE
WHEN a.AddressID IS NOT NULL
THEN 1 ELSE 0
END) AS scopeCount,
SUM(CASE
WHEN a.AddressID IS NULL
THEN 1 ELSE 0
END) AS nonCompliant
FROM Sales.Customer c
LEFT JOIN Person.BusinessEntityAddress ba ON c.PersonID = ba.BusinessEntityID
LEFT JOIN Person.Address a ON ba.AddressID = a.AddressID
WHERE ba.AddressTypeID IN (2, 3) -- Billing and ShippingRule Name: Product_Price_Change_Consistency
Description: Flags products with >50% price changes in single update
Data Quality Dimension: Consistency
Schedule: Daily
Target: Production.ProductListPriceHistoryWITH PriceChanges AS (
SELECT
ProductID,
ListPrice,
LAG(ListPrice) OVER (PARTITION BY ProductID ORDER BY StartDate) AS PrevPrice,
CASE
WHEN LAG(ListPrice) OVER (PARTITION BY ProductID ORDER BY StartDate) > 0
THEN ABS(ListPrice - LAG(ListPrice) OVER (PARTITION BY ProductID ORDER BY StartDate)) /
LAG(ListPrice) OVER (PARTITION BY ProductID ORDER BY StartDate)
ELSE 0
END AS PriceChangePercent
FROM Production.ProductListPriceHistory
)
SELECT
COUNT(*) AS total_count,
SUM(CASE WHEN PriceChangePercent <= 0.50 THEN 1 ELSE 0 END) AS scopeCount,
SUM(CASE WHEN PriceChangePercent > 0.50 THEN 1 ELSE 0 END) AS nonCompliant
FROM PriceChanges
WHERE PrevPrice IS NOT NULL