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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Tom_G
Helper II
Helper II

Average by category measure

I have a table like below.

 

Shop    Cities                Number of Employees

A             New York                         5

B             Paris                                 6

C             New York                         7

D            London                             5

E             Paris                                 6

F             New York                          8

 

I want to create a measure to calculate the Average Number of Employees per City and put it in a table visual like below.

 

Shop    Number of Employees     Avg Number of Employees per City

A                         5                                                      6.6

B                         6                                                      6

C                         7                                                      6.6

D                         5                                                      5

E                         6                                                       6

F                          8                                                     6.6

 

I don’t want to create a column for the average number of employees per city and then a measure referencing it cause I need a dynamic measure that can be sliced by other categories not shown above, like shop type for example.

 

What i'm struggling with is how to get the avg per city on each line of the table visual, when the city is not in the visual or in the tab slicers?

 

Thanks for any help

 

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Tom_G 

Try this measure:

Avg Number of Employees per City = 
VAR _CITY = MAX('Table'[City] ) RETURN
CALCULATE(
    AVERAGE('Table'[NumberofEmployees]),
    'Table'[City] = _CITY,
    REMOVEFILTERS('Table') 

)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@Tom_G 

Try this measure:

Avg Number of Employees per City = 
VAR _CITY = MAX('Table'[City] ) RETURN
CALCULATE(
    AVERAGE('Table'[NumberofEmployees]),
    'Table'[City] = _CITY,
    REMOVEFILTERS('Table') 

)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi @Fowmy thanks for the measure it works well! 

amitchandak
Super User
Super User

@Tom_G , Assume Number of Employees is a column

 

calculate(sum(Table[Number of Employees]) , filter(allselected(Table), Table[City] = max(Table[City]) ) )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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