Forum Discussion

geiratatea's avatar
geiratatea
Frequent Visitor
4 years ago
Solved

Write robust DAX code which is easy to debug and performs well

Hi!

 

I have a very general question but I think many developers are searching for an best possible approach writing good dax formulas. Few days ago I saw a nice written dax code (which I cannot remember:-( ) But anyway, it was building a measure, that first created some selected filters into some variables, then it started to build up a virtual small table and added the filter sto it.

 

Next, it added one column through the ADDCOLUMNS functions which also included some local variables and additional logic.

 

The again a new variable filter was created, and put into the virtual table. And so on... Finally we get a spot on data table where we could the measure value we wanted. I though this was an elegant way to create measures and perhaps it is easier to debug the dax code as well. And perhaps this approach can even get better performace.

 

So my question is: Is this a good way to write dax code or do you have even better suggestions solving dax calculation problems? Examples would be grate.

 

Regards Geir

3 Replies

  • Hi:

    There are serveral places to help format code correctly. 

    https://www.daxformatter.com/   for one.

     

    You can also use DAX Studio, Dax.do. TabularEditor(3)

     

    You'll notice they have both Long and Short form methodes for writing the code. Any of these choices should help you see the correct(accepted) way of writing DAX. I hope this answers your question. Thanks..