Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi all - do you ever find yourself using Variables in DAX when it's not 100% neccesary just so the DAX looks nice?
I'm noticing that using variables makes the code look so much cleaner
Solved! Go to Solution.
Thanks for the reply, sir. Quick question about #5 Helps in creating virtual table which can be used in optimizing the cod"
When do you see yourself creating virtual tables, why do you do it, and how does it help you. I've seen so many videos of folks doing this, but I've never had to use it myself. I'd usually create customized tables in Power Query - though I know a lot of people create these virtual tables with DAX.
Can't you still aggregate the same way without virtual tables?
@Anonymous Yup, I use variables even if the code without variables is still shorter and readable enough. However I have my own reasons to use variables everytime.
1. Readability
2. I know that execution happens only once
3. I know that execution happens only where I have declared the variable
4. I can reuse the value again and again
5. Helps in creating virtual table which can be used in optimizing the code
6. Helps in switching between Strict and Eager evaluation which can also be done with IF.EAGER but Variables improve readability
7. Query plan generated with Variables is much more readable and easy to understand, example below, just by looking at the Logical Query Plan I can decipher where a variable is declared and where it is used.
Thanks for the reply, sir. Quick question about #5 Helps in creating virtual table which can be used in optimizing the cod"
When do you see yourself creating virtual tables, why do you do it, and how does it help you. I've seen so many videos of folks doing this, but I've never had to use it myself. I'd usually create customized tables in Power Query - though I know a lot of people create these virtual tables with DAX.
Can't you still aggregate the same way without virtual tables?