cancel
Showing results 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

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
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
3 REPLIES 3
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
Helper II

Hi @Fowmy thanks for the measure it works well!

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]) ) )

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors