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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ania_roh
Helper III
Helper III

doubt with DAX expression

Hello.

I´m learning Dax and there is one thing which I don´t understand. Could you help me to understand the reason of why the result of these expressions are like that?

If I use for example this expression, the result I obtain is what I want obtain

 

 (by the way, I understand that using “all” and “summarize” in this case has the same meaning, isn´t it?)

 

ania_roh_0-1636800017824.png

 

 

ania_roh_1-1636800034323.png

 

The problem is when I want to use expression instead of measure (sales amount) I mean:

Sales amount = sumx ( net price * quantity) like that:

 

ania_roh_2-1636800063582.png

 

The result is incorrect ( using “all” the same). The result is the sum of the all sales, for every row. Why is it like that if I put just the same expression in the measure?

 

Thank you in advance

 

 

 

1 ACCEPTED SOLUTION

Hi,

Inside ADDCOLUMNS,

the first two examples are using the measure, [Sales Amount]

the last example is using the expression, SUMX( Sales, Sales[Price] * Sales[Quantity] )

 

 

Please try to use the below if you want to write an expression when creating a table.

 

Categories Table =
ADDCOLUMNS (
SUMMARIZE ( 'Product', 'Product'[Category], 'Product'[Subcategory] ),
"@sales", CALCULATE ( SUMX ( Sales, Sales[Price] * Sales[Quantity] ) )
)

 

 

Those two functions are different functions.

Sometimes, ALL and SUMMARIZE do the same job, sometimes do not.

 

My preference is writing like below. But it depends on the case.

 

Categories Table =
SUMMARIZECOLUMNS (
'Product'[Category],
'Product'[Subcategory],
"@sales", SUMX ( Sales, Sales[Price] * Sales[Quantity] )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

When you use a measure inside another measure, in some cases, for instance, if you use an iterator, it creates Context-Transition-Environment.

When you do not use a measure, but an expression, inside another measure, you may think whether or not to use CALCULATE function in front of your expression in order to create Context Transition when you are using together with an iterator.

In this case, instead of only writing an expression,

in front of SUMX, try to write CALCULATE( your expression ).

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you @Jihwan_Kim  for your quick answer. 
I didn´t exactly understand what you mean by "using a measure inside another measure" because I have here only one measure inside one table (summarize). 

Is it related with a row- contects ? How many row context I have here?

And also, do I understand good that in this case "all" and "summarize " have the same functions?  (There is no difference between them? ) 

Thank you a lot for your time 🙂 

Hi,

Inside ADDCOLUMNS,

the first two examples are using the measure, [Sales Amount]

the last example is using the expression, SUMX( Sales, Sales[Price] * Sales[Quantity] )

 

 

Please try to use the below if you want to write an expression when creating a table.

 

Categories Table =
ADDCOLUMNS (
SUMMARIZE ( 'Product', 'Product'[Category], 'Product'[Subcategory] ),
"@sales", CALCULATE ( SUMX ( Sales, Sales[Price] * Sales[Quantity] ) )
)

 

 

Those two functions are different functions.

Sometimes, ALL and SUMMARIZE do the same job, sometimes do not.

 

My preference is writing like below. But it depends on the case.

 

Categories Table =
SUMMARIZECOLUMNS (
'Product'[Category],
'Product'[Subcategory],
"@sales", SUMX ( Sales, Sales[Price] * Sales[Quantity] )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Fsciencetech
Helper III
Helper III

Can you please sample pbix and also check once your datamodel.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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