- There is an important rule you always need to remember.
It is not formatted, it is not DAX.
Format your code. That's super important.
And that's one of the reasons why DAX Formatter
allows you to format your code in a very simple way.
It is directly connected with the daxfordmatter.com website
and gives you the option of using
both the short line and the long line format
to have a more compact version of your DAX code
or a more longer one if you have a lot of lines of code.
Let's see how it works.
We still have the query we have generated,
we can now close the query editor also reduce this a bit
and also this.
So, this is the query that was
generated by the query editor.
You see it's kind of long and it is not formatted properly.
There is a button here.
If I can... if I click it, it will format the code.
But before doing that let's analyze briefly
what are the options available.
You can choose the long line or the short line.
One is the default, the other one is the alternate
way of formatting the code.
You can choose the default in the options.
So, if I just click, it will use the long line.
And there is also a keyboard shortcut that again
can be changed using the option, but by default it's F6
for the default formatting and control + F6
for the other one.
Let's do that together.
I'm going to use the keyboard.
If I use F6, the query is formatted and you see
it is right now using the long line format
which is the default.
Let me check it.
Yes, by default I'm using the long line.
The lines are kept somewhat long but the code is short.
So, it uses less lines.
But anyway, it's much more readable than before.
If I use control + F6 then it's going to use
the other format, which
in this case is definitely bad because you see
that all the lines are shorter, but functions like these
where each argument is separated in its own line
is really hard to read.
So, you need to choose between long line
and short line in a wise way, depending on the kind of code
that you write and depending on your personal habits.
I would prefer for this for sure the long line format.
Now the code is much more readable.
You can configure everything
in the options under DAX Formatter.
You can choose the default format style
between long line and short line
and you can also choose whether you want
to skip the space after the function name or not.
Personally, I prefer to leave the space
after the function name
but I know somebody does not like the space
after the function name.
So, if you check it and then you go back, look here
there is a space immediately after every function name
but if I format the code now, that space will be removed
and now it is closer to the function.
Before doing anything else
let me just remove it and format the code again.
The other thing that you can change
is the shortcut for the keyboard.
Again in the key bindings you have the option
of choosing how to format your query and how to
format the query in the alternate style.
So, one of the good things
about DAX Studio is that it gives you the option
of formatting the code in a seamless way.
That means right now you have no excuses at all.
If your code is not formatted
just open DAX Studio, format it
and only then start reason on top of it.
There are so many mistakes that can be simply solved
by formatting your code the proper way.