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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
felipereyes_
Frequent Visitor

Calculating Average of a measure within a hierarchy

Hi everyone,

 

I need to solve an issue that I am having with DAX, but I cant find the right query.
To give you some context: I have different regions in my data that have the values T100, T200, T300 and so on. They can be found in the column RegionLevel2 in the table Geography. Then , in the same table there is a column called TerrLevel1 that has the territories. Each region has multiple territories. So for example the territories for region T100, are T101, T102, T103 and so on. For each of these territories I have calculated a Score, based on their individual sales. It is a measure called Score1 and working fine. Now I need to calculate the score for the regions. This score is based on the average of the sales of a regions territories. So in the case of T100, its score would be the average of the Score1 of T101, T102, T103 and so on. I have tried these DAX 

AVERAGEX(Geography, [Score1])

AVERAGEX(all(Geography[TerrLevel1]), [Score1])
 
AVERAGEX(VALUES(Geography[TerrLevel1]), [Score1])
 
CALCULATE(
                        AVERAGEX(Geography, [Score1]),
                        ALL(Geography[TerrLevel1]))

but it is not giving me the right result. I guess i need to filter somehow to group the right territories with their region but I cant figure out how.
 
I would appreciate any kind of help. Thank!
3 REPLIES 3
lbendlin
Super User
Super User

You cannot measure a measure.  Either materialize it, or create a new measure that implements the entire business logic.

Hi! So you would recommend me to create a measure that includes the calculation on Score1 and also the average of that score to get the score for the regions? I assume I would need to create temporary tables. If we assume that the calculation of score1 inside of that measure is VAR Score1= [Price] * [Units] , how would I calculate the average for each region?

Here's the pseudo code:

 

SUMMARIZECOLUMNS(Region)

ADDCOLUMNS(score measure)

Return AVERAGEX

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors