Code action DR004
(Readability) Prefix variable
Description
It is recommended to use a consistent prefix for variables, to more easily distinguish them from table references. The default prefix is _
, but you can configure which prefix to use, to match your preferred style, under Tools > Preferences > DAX Editor > Code Actions.
Example
Change:
VAR sales = SUM('Internet Sales'[Sales Amount])
RETURN sales * 1.25;
To:
VAR _sales = SUM('Internet Sales'[Sales Amount])
RETURN _sales * 1.25;
Why is Tabular Editor suggesting this?
This code action is designed to improve the readability of your DAX code. By using a consistent naming convention for your variables, it is easier to understand the purpose of each variable, and to distinguish between variables and tables.
Moreover, using a special character (such as an underscore) as a prefix for variables can help to avoid naming conflicts with table names, in case a table with the same name as the variable is added to the model in the future.
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.