Code action DI004
(Improvement) Add table name to column references
Description
Column references should always include the table name to avoid ambiguities, even when the table name is optional.
Example
Change:
SUMX('Internet Sales', [Line Amount] * [Quantity])
To:
SUMX('Internet Sales', 'Internet Sales'[Line Amount] * 'Internet Sales'[Quantity])
Why is Tabular Editor suggesting this?
Since measure names are always unique within a model, it is always possible to reference a measure without specifying the table name. However, column names are not unique within a model, and it is therefore necessary to specify the table name when referencing a column, such as when using one of the aggregation functions, i.e.: SUM('Sales'[Amount])
.
However, there are situations in which the table qualifier is optional for column references. For example, this is the case when the column exists within an active row context (such as inside a Calculated Column). Even so, providing the table name in this case is still valid, and helps avoid ambiguities and errors in case a measure with the same name is eventually added to the model.
By applying this practice consistently, you make your code more concise and easier to read, and you make it easier to distinguish between measure references and column references.
Remarks
This code action has an (All occurrences) variant, which will appear when multiple sections of code can be improved. This variant will apply the code action to all relevant sections of the document at once.