Rules / Error Prevention

Relationship columns should be of the same data type

error RELATIONSHIP_COLUMNS_SAME_DATA_TYPE · ported · model layer · scope: Relationship

What it checks

Relationships whose two columns have different data types.

Each finding names the relationship the way Tabular Editor does, 'Sales'[Product ID] ∞←1 'Product'[Product ID], with the two cardinalities either side of an arrow that points the way the filter travels. The types themselves are not in the line, so read the two columns to see which one to change.

Example

Fires the rule
table Sales
	column 'Product ID'
		dataType: string
		sourceColumn: ProductID

	column Amount
		dataType: decimal
		sourceColumn: Amount

table Product
	column 'Product ID'
		dataType: int64
		isKey
		sourceColumn: ProductID

	column 'Product Name'
		dataType: string
		sourceColumn: ProductName

relationship Sales_Product
	fromColumn: Sales.'Product ID'
	toColumn: Product.'Product ID'
After the fix
table Sales
	column 'Product ID'
		dataType: int64
		sourceColumn: ProductID

	column Amount
		dataType: decimal
		sourceColumn: Amount

table Product
	column 'Product ID'
		dataType: int64
		isKey
		sourceColumn: ProductID

	column 'Product Name'
		dataType: string
		sourceColumn: ProductName

relationship Sales_Product
	fromColumn: Sales.'Product ID'
	toColumn: Product.'Product ID'

Why it matters

The engine relates columns by value, and when the types differ it converts one side for every query. A text key on one side and a whole number on the other works until a value like 007 meets 7, at which point rows quietly fall into the blank member. Matching types remove both the conversion cost and the surprise.

How to fix it

Set the two columns to the same type, and prefer a whole number for a key. In Power BI Desktop there are two places to do it: Column tools, Data type on the selected column, which changes the type on the model, or Transform data, where a Changed Type step in Power Query gets the type right before the data is loaded and keeps it right on every refresh. Power Query is the better of the two when the source is the reason the types differ. In the TMDL file the property is dataType on each column. Converting a text key to a whole number fails at refresh on any value that is not a number, so look for padded keys such as 007 first and strip the padding in the same Power Query step.

When to ignore it

There is nothing to ignore: where both columns name a type and the types differ, set them to the same type. The rule compares only the types the TMDL names, so a relationship with a calculated column saved with no dataType line is not reported at all (see Quirks).

To ignore this rule on one object, add annotation pbiplint.ignore = RELATIONSHIP_COLUMNS_SAME_DATA_TYPE under the object in its TMDL file. Power BI Desktop keeps the annotation. To turn the rule off for a whole project, set "RELATIONSHIP_COLUMNS_SAME_DATA_TYPE": "off" under rules in pbiplint.config.json.

Quirks

Ported from Microsoft's Best Practice Analyzer ruleset (opens in a new tab).

Check a model for this Improve this page (opens in a new tab)