Quantcast
Channel: SQLBI
Viewing all articles
Browse latest Browse all 434

Avoid measure and column with the same name in #dax

$
0
0

I recently wrote an article about duplicated names in DAX to highlight a possible case where you can have a measure with the same name of a column. This is not a good idea, mainly because the syntax to reference a measure and a column is identical, and this similarity is the root of a number of issues. It would be much better if the measure reference had a syntax different from the column reference.

The syntax table[identifier] could identify either a column or a measure, and there is no secure way to understand that by just reading the code (unless you look at the color highlighting). I thought to a list of techniques to disambiguate that syntax, and the only available one is to modify the measure reference (not the column reference) in one of these ways:

  • CALCULATE ( table[identifier] ) is a syntax that certainly reference a measure, if table[identifier] is a column, the lack of a row context in CALCULATE would generate an error
  • table[identifier]() is another way to invoke a measure, which in reality corresponds to CALCULATE ( table[identifier] ); if you use DAX Formatter, a syntax like [measure]() is transformed in CALCULATE ( [measure] ); however I might consider modifying DAX Formatter if it was necessary. However, I don’t think that a syntax such as [measure]() is more readable.

If it was possible to refactor the DAX syntax, I would use a different syntax for a measure reference:

  • (measure)
  • {measure}
  • [other ideas?]

It’s probably too late for a similar discussion, but you never know.

Feedbacks are welcome.


Viewing all articles
Browse latest Browse all 434

Trending Articles