cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Variable Help

Hi Power BI experts

I am still learning Power BI. And I am confused about this variable concepts.  Could you pls help explain a little bit?  Thank you!

Example:

Sales[Order Position]=
1 VAR CurrentOrderNumber= Sales[Order Number]

2 Var Postion=
Calculate (

DISTINCTCOUNT(Sales[Order Number]),

Sales[Order Number]<=CurrentOrderNumber  //My confusion is here.  Is this the same column?  Both refer to same Sales[OrderNumber] since CurrentOrderNumber=Sales[Order Number]? //
)
Return  Position

2 ACCEPTED SOLUTIONS
Super User

once defined, the variable is stored as constant value.  so in expression like:

Sales[Order Number]<=CurrentOrderNumber

the left part is a real variable row by row, the right part is actually a constant defined before.

Anonymous
Not applicable

Hi @RZAU ,

For understand VAR statement, you should understand the context concept in Power BI, because it is influence by context.

VAR: Stores the result of an expression as a named variable, which can then be passed as an argument to other measure expressions. Once resultant values have been calculated for a variable expression, those values do not change, even if the variable is referenced in another expression.

Sales[Order Position] =
VAR CurrentOrderNumber = Sales[Order Number] //get current value for [Order Number] column according to the line context
VAR Postion =
CALCULATE (
DISTINCTCOUNT ( Sales[Order Number] ),
Sales[Order Number] <= CurrentOrderNumber //use the CurrentOrderNumber to filter the [Order Number]column, now CurrentOrderNumber is just a value not a column
)
RETURN
Position

For more details, you can read related document: VAR keyword (DAX) - DAX | Microsoft Learn , Variables in DAX - SQLBI

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 REPLIES 2
Anonymous
Not applicable

Hi @RZAU ,

For understand VAR statement, you should understand the context concept in Power BI, because it is influence by context.

VAR: Stores the result of an expression as a named variable, which can then be passed as an argument to other measure expressions. Once resultant values have been calculated for a variable expression, those values do not change, even if the variable is referenced in another expression.

Sales[Order Position] =
VAR CurrentOrderNumber = Sales[Order Number] //get current value for [Order Number] column according to the line context
VAR Postion =
CALCULATE (
DISTINCTCOUNT ( Sales[Order Number] ),
Sales[Order Number] <= CurrentOrderNumber //use the CurrentOrderNumber to filter the [Order Number]column, now CurrentOrderNumber is just a value not a column
)
RETURN
Position

For more details, you can read related document: VAR keyword (DAX) - DAX | Microsoft Learn , Variables in DAX - SQLBI

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Super User

once defined, the variable is stored as constant value.  so in expression like:

Sales[Order Number]<=CurrentOrderNumber

the left part is a real variable row by row, the right part is actually a constant defined before.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

#### Power BI Monthly Update - July 2024

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

#### Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors