Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Variables? Why?

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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?

View solution in original post

2 REPLIES 2
AntrikshSharma
Community Champion
Community Champion

@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.

 

AntrikshSharma_0-1632423673628.png

 

Anonymous
Not applicable

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?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors