cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MarkusBohse
Regular Visitor

How to calculate average over a subset of all

I'm having three tabels like this:
Employee (EmpID, name, EmployeeAge, companyID,...)
Comapny (CompanyID, Name, RegionID)
Region (RegionID, Name)
 
What I need is a calculation of the average EmployeeAge for the selected company, the whole region and overall.
The first one is easy and so is the last one using the ALL function. But I'm struggling to get the average for the region of the selected company.
I had a look at ALLEXCEPT, but so far I cannot get to return the correct result.
Any hints are appreciated
1 REPLY 1
Anonymous
Not applicable

-- If the structure is:
-- Employee[CompanyID] * : 1 Company[CompanyID]
-- Company[RegionID] * : 1 Region[RegionID],
-- then:

[Avg Employee Age] = AVERAGE( Employee[EmployeeAge] )

-- This measure calculates the average age
-- of all employees that work in companies
-- that belong to regions that are visible
-- in the current context. For instance,
-- if one employee has been selected, then
-- it'll return the average age for the
-- region to which the company of the employee
-- belongs.

[Avg Age for Regions] =
var __visibleRegions =
	SUMMARIZE(
		Employee,
		Region[RegionId]
	)
var __avgForVisibleRegions =
	CALCULATE(
		[Avg Employee Age],
		ALL( Company ),
		__visibleRegions
	)
return
	__avgForVisibleRegions

This measure honors all the filters that have been put on the Empolyee table itself.

 

Best

Darek

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors