Power BI Antipatterns #13: Naming conventions

Some people say that naming is the hardest aspect in coding. Today’s blog post is about naming conventions.

For today’s examples, I borrowed a formula from DAX Patterns and adapted it to my needs 🙂

Here’s a typical example:

I doubt there are people for whom variable names such as A, B, C, D, and E mean anything, and yet it’s fairly common to see such meaningless names. Perhaps you could say those variable names are surrogate, like surrogate keys?

When you’re the one who’s writing the formula, it’s not so difficult to understand it, as long as the formula is not too complex and not too much time has passed since you last saw the formula. For someone else though, if variables don’t have good names, then it’ll be difficult to understand what they are.

Here’s a much better way to write the same formula:

Note how each variable name now tells you what it’s doing, so the formula is much easier to understand even if you’ve never seen it before.

When you’re writing very complex formulas, it might be a good idea to leave comments like so:

Note: interested in how you can comment something in your code quickly? Check out my blog post on keyboard shortcuts: DAX formula bar keyboard shortcuts in Power BI Desktop – XXL BI

With comments, your formulas are as clear as they can be. While sometimes highly complex DAX can be a sign of having a suboptimal data model, sometimes complex DAX is justified and comments can aid its understanding.

Of course, naming conventions apply to more than just DAX variables; Chris Webb wrote a great blog post on the topic: Naming Tables, Columns And Measures In Power BI. In short, naming conventions can be beneficial to data model developers, report builders, as well as end users because naming conventions promote consistency, readability, and clarity.

To be continued…