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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
bboy0009
Helper II
Helper II

To create or not a var in a DAX formula

Hi guys,

Hope you're doing well.

 

I wonder what is the impact of creating VAR in a DAX formula. I have formulas like below : 

var CB1111_vs_ns=DIVIDE([Direct COGS Ref],[Net Sales Ref])
var CB1120_vs_ns=DIVIDE([Indirect COGS], [Net Sales Ref])

I use them in a SWITCH in the return part.

These VAR are very simples so I think that I could write directly them in the switch so my formula is shorter and maybe it could optimize the performance. The goal is optimize as much as possible the performance.

 

Could you advice me ?  

Thank you 

3 REPLIES 3
Idrissshatila
Super User
Super User

Hello @bboy0009 ,

 

so Var stands for variable, you would use it with you want to create a measure that needs multiple calculations so instead of creating multilple measures and then using them in one, you could do all this in one measure by using variables.

 

a simple example:
these are three measures to get the profit:

 

Total revenue =  sum (revenue)

Total Cost = sum ( cost)
Profit = Total revenue - Total Cost

 

Now will do the same in one measure and still get same result:

 

Profit =

var revenue = sum ( revenue)

var cost = sum(cost)

return
revenue - cost

 

 

you could also check this article https://www.sqlbi.com/articles/variables-in-dax/

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Follow me on Linkedin



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




please just don't answer just for answer like so many

come on please read the post first before answering

I didn't ask you what is a VAR. I asked for performance's questions 

Thank you anyway !

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors