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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
powerbiexpert22
Impactful Individual
Impactful Individual

variable in DAX expression

what standards or best practices we should follow while defining the variables (including variable name) in DAX expression

2 ACCEPTED SOLUTIONS
foodd
Super User
Super User

Hello @powerbiexpert22 ,  SQLBI covers the topic well in their article titled Variables in DAX, a part of the DAX101 Series.

 

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.  Proud to be a Super User!

View solution in original post

Anonymous
Not applicable

Hi  @powerbiexpert22 ,

 

There are no standardized rules for defining variable names. Personally, I usually start my variable names with two "_" so I can quickly determine which one is the variable. This also makes it easier to call them quickly.

VAR __variablename = ...


It is also recommended that variable names describe this step as much as possible. Avoid using meaningless characters such as "a", "b", "c", etc. as variable names.

The advantage of variables is that they are calculated only once for each variable (it is important to note here that variables are calculated at the time of definition, not at the time of use), and can be replaced with variables for frequently used parts.

The use of variables after RETURN instead of expressions is useful when checking the results of intermediate steps, and you can always replace the variables after RETURN to check the results.

Hope these help.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @powerbiexpert22 ,

 

There are no standardized rules for defining variable names. Personally, I usually start my variable names with two "_" so I can quickly determine which one is the variable. This also makes it easier to call them quickly.

VAR __variablename = ...


It is also recommended that variable names describe this step as much as possible. Avoid using meaningless characters such as "a", "b", "c", etc. as variable names.

The advantage of variables is that they are calculated only once for each variable (it is important to note here that variables are calculated at the time of definition, not at the time of use), and can be replaced with variables for frequently used parts.

The use of variables after RETURN instead of expressions is useful when checking the results of intermediate steps, and you can always replace the variables after RETURN to check the results.

Hope these help.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

foodd
Super User
Super User

Hello @powerbiexpert22 ,  SQLBI covers the topic well in their article titled Variables in DAX, a part of the DAX101 Series.

 

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.  Proud to be a Super User!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.