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
SiroPW
Helper I
Helper I

Average of Category (across tables)

Hi All,

 

I feel like this is something that should be simple but I can't find the magic bullet after trying a lot.

 

I have 2 linked tables (Many to 1):

 

Table A:

nameageid
abc201
abc301
xyz502
xyz602
def703

 

Table B:

valueid
1001
2002
3003

 

I'd like to be able to output the value of each id by their average age.

So id 1, the average age from table A would be 25.

 

Output would be like so:

avg_agevalue
25100
55200
70300

 

I have tried a lot of combinations with CALCULATE, AVERAGEX, ALLEXCEPT, FILTER and still can't get it, hope I have outlined the problem well enough.

 

Thanks for any help.

1 ACCEPTED SOLUTION

Hi @SiroPW ,

 

 

You can just create a Calculated Column.

 

 

Average Age = CALCULATE(Average('Table'[age]),ALLEXCEPT('Table','Table'[id]))
 
1.jpg
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

5 REPLIES 5
AllisonKennedy
Super User
Super User

What additional filters or slicers do you need to work with this? You should just be able to do a standard average, just need to use the correct columns in the visual. Create a new MEASURE: 

Average Age = AVERAGE(TableA[Age])


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

I think I have explained this poorly.

 

Let me simplify..

 

Given this Table A:

Table A:

nameageid
abc201
abc301
xyz502
xyz602
def703

 

How do I add a new column (average age based on the id) such that Table A is now:

Table A:

nameageidavg_age
abc20125
abc30125
xyz50255
xyz60255
def70370
Anonymous
Not applicable

Why do it in DAX? Isn't it sooooo much easier (and better!) to do it in Power Query? If you do it in PQ and the table is big, it'll not only be faster but you'll get optimal compression, which is not possible through DAX.

Be careful with code as given by harshnathani. If the table is big (think: fact table), CALCULATE will execute context transition for each and every row which will be extremely costly and can easily lead to out-of-memory errors.

Best
D

Hi @SiroPW ,

 

 

You can just create a Calculated Column.

 

 

Average Age = CALCULATE(Average('Table'[age]),ALLEXCEPT('Table','Table'[id]))
 
1.jpg
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Why do you need it as a column? If you create the MEASURE, it can be used in a table visualization. Can you please elaborate on your requirements so we can help further? I generally don't recommend doing aggregations (such as average) in a calculated column as this can be used incorrectly in visuals and cause incorrect information later. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.

Top Solution Authors