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
mgirvin
Advocate I
Advocate I

DAX Iterator Efficiency: Formula or Measure in Second Argument of AVERAGEX?

 

DAX Iterator Efficiency: Formula or Measure in Second Argument of AVERAGEX?

 

Dear Team,

 

I have a Fact Table named fTransactions with 3,360 rows.

 

I have created this Measure to sum the Transactional Line Item Revenue from a Fact Table:

 

Measure [1] is as follows:

Total Revenue :=

SUMX (

   fTransactions,

   ROUND ( RELATED ( dProduct[RetailPrice] ) * fTransactions[Units], 2 )

)

 

Next, I would like to create a Measure to average the Transactional Line Item Revenue from a Fact Table. But my question is: “Should I use a Measure in the second argument of AVERAGEX or repeat the formula?” The two measures I am considering are listed here:

 

Measure [2] is as follows:

Ave Transactional Rev 2nd is Formula :=

AVERAGEX (

   fTransactions,

   ROUND ( RELATED ( dProduct[RetailPrice] ) * fTransactions[Units], 2 )

)

 

Measure [3] is as follows:

Ave Transactional Rev 2nd is Measure :=

AVERAGEX ( fTransactions, [Total Revenue] )

 

I am asking this question because it seems to me that in Measure [3] there are two iterations over the Fact Table, and maybe this is inefficient?

 

When I run the two formulas in DAX Studio to time and look at query plan (I am a novice at reading all this), I can see:

 

  1. Measure [2]
    1. Physical Query Plan has 16 lines
    2. The largest number of records in the Physical Plan is 1
    3. For the Server Timings: FE = 1 ms and SE = 1 ms
    4. In the Server Query Tab I see one Query
  2. Measure [3]
    1. Physical Query Plan has 19 lines
    2. The largest number of records in the Physical Plan is 3,360
    3. For the Server Timings: FE = 2 ms and SE = 2 ms
    4. In the Server Query Tab I see two Queries

There are other details in DAX Studio too. But it seems to me like the DAX Studio information is suggesting that Measure [3] with the Measure in the second argument of AVERAGEX has to work harder.

 

Any ideas that can help me to understand more completely which version to use for calculating the average of the Transactional Line Item Revenue? Measure [2] or Measure [3]?

 

Sincerely, Mike Girvin

1 ACCEPTED SOLUTION

Okay, I guess I answered my own question. In the first post I was comparing Measure [2] and [3] using a 3000 row table. I just tried the comparison on a 2 million row table, and the DAX Studio information clearly shows that the Measure [3] takes much longer to calculate and has to internally materialize larger tables. So it looks like Measure [3] is having to work harder. Further, if I do not want the risk of double counting because of the Contact Transition converting the Row Context into Filter Context when there are duplicates or no primary key, then it would make sense to use Measure [2], the one with the formula in the second argument rather than the Measure.

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

My guess here is that you are correct and Measure 3 is inefficient. But, the real expert on that topic would likely be @marcorusso.


Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Is Marco Russo the only expert that can answer this conceptual/technical question? Anyone else?

Okay, I guess I answered my own question. In the first post I was comparing Measure [2] and [3] using a 3000 row table. I just tried the comparison on a 2 million row table, and the DAX Studio information clearly shows that the Measure [3] takes much longer to calculate and has to internally materialize larger tables. So it looks like Measure [3] is having to work harder. Further, if I do not want the risk of double counting because of the Contact Transition converting the Row Context into Filter Context when there are duplicates or no primary key, then it would make sense to use Measure [2], the one with the formula in the second argument rather than the Measure.

That makes sense, @Greg_Deckler, because the conceptual DAX knowledge and DAX Studio techniques I am applying here, I learned from Macro Russo's @marcorusso class and book : ) I was posting here to try and verify that then way I am thinking about this is correct.

Thanks for post back, Greg!

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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