Power BI is a great platform with amazing capabilities. However, it also has its dark areas, and in my opinion, one of them is how to document calculations and model logic.
In simple projects, it can be managed without documentation. But in complex projects, with specific metrics and involving multiple people, it becomes more necessary. Therefore, the efforts put into documentation should be rewarded in the medium term.
At TEFIPRO, we encounter the situation described above: several people work on a project as it evolves, with very specific metrics that are sometimes beyond general understanding.
As far as we know, there are no guidelines established by any relevant entity or widely accepted by the community. Therefore, this entry aims to share how we do it. (It doesn’t have to be the best way, but it is useful for us.)
Use of Variables
Variables are useful from the efficiency perspective in calculations but also to break down the code into smaller steps, making the calculation more progressive and understandable.
Variable Names
Variables have some limitations from a ‘naming’ perspective, primarily that they cannot contain spaces. With the goal of making our code readable, our approach is as follows:
Use descriptive names: Initial analysis date (fecha inicial de análisis)
Use the underscore character to allow multiple words in the variable name: Initial_analysis_date
Use capital letters at the beginning of words: Initial_Analysis_Date
The third point is more open to debate, but personally, it helps me read and understand the variable more quickly. DAX, the language of Power BI, is not case-sensitive, so this third point won’t cause errors if we forget to capitalize while writing the formula.
Comments
Making precise comments in the code helps with future understanding and also allows for clarifying ideas during development.
When the metric is very specific, it is useful to describe it at the beginning.
At the variable level, you can also specify details through comments, such as indicating units or other hints that help maintain the code in the future.
Formatting and Indentation
Using indentation properly contributes to the goal of making our code more understandable and also helps avoid errors with ‘(‘ … ‘)’ or ‘,’
In contrast to:
To start organizing indentation properly, tools like https://www.daxformatter.com/ can be used. In our experience, after using this tool a couple of times, you naturally start writing with correct formatting, making any additional tool unnecessary.