Skip to main content
cancel
Showing results for 
Search instead 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

Reply
JPDUVAL76
Helper I
Helper I

DAX with VAR

Hello,

I don't understand why these two DAX codes don't return the same amount in Power BI. In my example, imagine a table with 4 columns:

- Date of receipt
- Amount of the receipt
- Receipt number
- Type

The type is "purchase order" when it equals 1 and "invoice" when it equals 2. I simply want to calculate the amount when the type is 1. I'm using this very simple example for the variables, but I could do it differently.

In my first case, my code is as follows:
```DAX
VAR status_bdc = 1
VAR BDC = [Amount]
VAR result = CALCULATE(BDC, CBonLivraison[TypeBon] = status_bdc)
RETURN result
```
Here, [Amount] = SUM(Amount of the receipt). In this case, "result" is not correct because it doesn't apply the filter Type = 1.

In the following code, it works:
```DAX
VAR status_bdc = 1
VAR BDC = [Amount]
VAR result = CALCULATE([Amount], CBonLivraison[TypeBon] = status_bdc)
RETURN result
```
The only difference is that in the first code, I call the variable BDC which contains the measure, whereas in the second case, I directly include the measure amount in my result variable.

If someone can explain to me because I don't understand the point of it if it doesn't work, I also tried putting Var BDC = SUM(Amount of the receipt) and it doesn't work.

Thanks in advance.

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

I see this regularly on the forum.  When you assign a measure to a variable, it gets evaluated (and won't change after that). There isn't a notion of some kind of dynamic evaluation where the variable holds the name of the measure and evaluates it at some later point.

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

I see this regularly on the forum.  When you assign a measure to a variable, it gets evaluated (and won't change after that). There isn't a notion of some kind of dynamic evaluation where the variable holds the name of the measure and evaluates it at some later point.

Thx for this answer, it's clear now !!!!

Helpful resources

Announcements
Europe Fabric Conference

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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors