Forum Discussion
Reading the Dax Code Easily
- 3 years ago
yigitersann Commenting code is always a recommended best practice for all coding languages, including DAX. You can also use the Description metadata field to help document or explain your calculation as well.
Also, if you want to really understand what is happening at each step of a calculation, use VAR's and then you can return what is in the VAR as the RETURN for the measure and essentially kind of step through the calculation, seeing what each VAR contains as you go. I often use CONCATENATEX to do this for a table VAR which is also yet another reason why I don't tend to use CALCULATE because CALCULATE obfuscates what is going on internally. https://youtu.be/meh3OkgFYfc
DAX Studio is really more about returning tables of values versus measures that return scalar values (single values, not a table of values). That is why your measure code doesn't work in it.
Greg_Deckler First of all, thank you a lot for your high quality explanations.
Also, do you think the best way to understand what the DAX code is doing is to add comments as you did, or can you suggest another way?
In my opinion, DAX Studio is very good for practice, but the code in power does not work in DAX Studio which I don't understand why.
yigitersann Commenting code is always a recommended best practice for all coding languages, including DAX. You can also use the Description metadata field to help document or explain your calculation as well.
Also, if you want to really understand what is happening at each step of a calculation, use VAR's and then you can return what is in the VAR as the RETURN for the measure and essentially kind of step through the calculation, seeing what each VAR contains as you go. I often use CONCATENATEX to do this for a table VAR which is also yet another reason why I don't tend to use CALCULATE because CALCULATE obfuscates what is going on internally. https://youtu.be/meh3OkgFYfc
DAX Studio is really more about returning tables of values versus measures that return scalar values (single values, not a table of values). That is why your measure code doesn't work in it.