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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
GSE
Resolver I
Resolver I

DAX Difference - Measure as variable vs. Measure directly in formula

Hi all, 

 

I would like to understand the difference between declaring a measure as a variable vs. using the measure directly in the formula without declaring it as a variable first.

 

What I noticed is that in the first example, the processing time is almost 8 times higher (when not declaring it as a variable) and in the second example the formula throws an error.

 

I know that if a measure is declared as a variable first, it is evaluated in the context of the visual but how is it evaluated when not declared as a variable and why does it take so much longer or throws an error.

 

Example 1

not declared as variable (processing time almost 8 times longer)

GSE_0-1682408884636.jpeg

declared as variable

GSE_1-1682408941882.jpeg

Processing time (first matrix is with declared variable and second matrix is without declared variable)

GSE_2-1682409002405.jpeg

 

 

Example 2

not declared as variable: error

GSE_3-1682409025643.jpeg

 

declared as variable: no error

GSE_4-1682409048046.jpeg

 

1 REPLY 1
lbendlin
Super User
Super User

The fun part here is that "variable"  actually means "constant".  You are basically turning the measure into an immutable value that will now no longer be recomputed in the following computations.

 

Power BI has no concept of (mutable) variables. These are all constants.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors