THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

SQLBI - Marco Russo

Please visit the same blog at - comments are now disabled here but you can comment on the new blog (all blog posts available here are available there, too).
You can follow me on Twitter: @marcorus

Avoid measure and column with the same name in #dax

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.

Published Tuesday, May 2, 2017 8:12 AM by Marco Russo (SQLBI)



Oxenskiold said:


May 3, 2017 1:13 PM

Marco Russo (SQLBI) said:

Why using table-> if the measure is unique in the model?

May 4, 2017 10:58 PM

Oxenskiold said:

Well I guess you have a point however to me a measure is only unique in name not in perception. [sum of something] can both be a measure and a column. The '()' and '{}' will make it parser friendly but no necessary human eye friendly viewed in a hurry. Table->measure could make it more obvious that a measure is referenced.

May 5, 2017 4:27 AM

Marco Russo (SQLBI) said:

But why the table name, then? Why not




The measure could be moved to another table at anytime.

May 5, 2017 4:34 PM
New Comments to this post are disabled

About Marco Russo (SQLBI)

Marco Russo is a consultant, writer and trainer specialized in Business Intelligence with Microsoft technologies. He runs the SQLBI.COM website, which is dedicated to distribute resources useful for BI developers, like Integration Services components, Analysis Services models, tools, technical information and so on. Marco is certified as MCT, MCDBA, MCSD.NET, MCSA, MCSE+I.

This Blog



Privacy Statement