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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
toddpbi
Helper II
Helper II

AVERAGEX - More than one row context on different tables

Hello everyone, a basic question here about row contexts.

I am trying to understand what this formula is actually calculating. I am reading the DAX book presented by Alberto Ferrari and have come across this formula when trying to understand context transition of calculate in the context of calculated columns. 

Product[SaleswithSUMX] = 
AVERAGEX ( 
                   Customer,
                   CALCULATE ( SUM ( Sales [Sales Amount] ) ) 


I do not exactly understand how you can have multiple iterations of both customers and products, and then how the sales table receives both the filters from customer and product (since this calculation is done within a calculated column context).


To my understanding, the way this formula works is the engine first calculates the total sales amount for the given product in the given row context in the product table due to context transition. It then iterates the Customer table and identifies how many customers bought this particular product, and then divides the total sales amount for that product by the amount of customers who bought the product to give the average price. 

 

Can anyone explain the order of the filters here? Does both the filters on the sales table happen simultaneously (from both customer and product)?

Any advice would be appreciated as I am trying hard to learn DAX but this is rather confusing for a beginner. I dont want to move on until I fully understand what is happening. 
Best,

1 ACCEPTED SOLUTION

I don't have that book, but if you look at the AVERAGEX, it is actually using the "Customer" table when computing the average. So, what I imagine is happening is that the AVERAGEX is computing the sales per customer but since it all being run within the row context of a Product, it becomes the average per customer per product. Really would need to understand the relationships between all of those tables but I can imagine that Sales is the fact table and Customers and Products are related to that table as essentially dimension tables.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
v-jiascu-msft
Employee
Employee

Hi @toddpbi,

 

Could you please mark the proper answers as solutions?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

DAX formulas are calculated from the inside out. So, what is going on there is that it is taking the customer table and calculating the sum of the product sales for each cusotmer. The CALCULATE provides the context transition since SUM does not understand row context. CALCULATE does understand row context. You then essentially do an average of each customer's product sales so what I would expect to end up with is the average of product sales for a product by customer. So, for each product customers buy on average x amount.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hi Greg_Deckler,

Thank you for the clarificaiton. 

What I don't understand is when you say "by customer", how do we exactly know what customer average we are talking about?
If it is a calculated column, the context transition of CALCULATE happens due to the presence of product information. In this case, the result is just an average of the total amount spent by all customers, right?

ie Product 1 has a total sales amount of $500, which is identified via context transition and CALCULATE. 5 customers bought the product, which is identified via the iteration on the cusotmer table, so the price spent per customer ends up being on on average $100.
Is this correct?

Cheers. 

I don't have that book, but if you look at the AVERAGEX, it is actually using the "Customer" table when computing the average. So, what I imagine is happening is that the AVERAGEX is computing the sales per customer but since it all being run within the row context of a Product, it becomes the average per customer per product. Really would need to understand the relationships between all of those tables but I can imagine that Sales is the fact table and Customers and Products are related to that table as essentially dimension tables.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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