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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
047
Frequent Visitor

Calculate regional average based on selected Country

Hi

A newbie in DAX, I'm looking for some help to create a measure. The relevant tables are structured as below with Regions[Country] 1-->* Sales[Country] relation.

 

Sales

-----------

Product

Country

Total Sales

etc...

 

Regions

----------

Country

Region

Sub-Region

 

I have a slicer for Region[Country]. I wasnt to display in a card visual the total/avg sales for the selected country, and the corresponding figures for the region & subregion. E.g., If I select Australia, I want to display the figures for the country Australia, sub-region Oceania and Region ASIAPAC. I want to build a DAX measure for the logic below:

 

select avg(Sales[Total Sales]) where Sales[Country] in (select Country from Regions where Region in (select Region from Regions where Regions[Country] = SELECTEDVALUE(Sales[Country]) )))

 

I've tried to search this forum and in general without luck. Here's what I was trying which obviously isn't working becasue I'm only filtering on the selected country.

 

AvgPerRegion = calculate(AVERAGE(Sales[Total Sales]), filter('Sales',search(SELECTEDVALUE(Regions[Country]),Sales[Country],1,BLANK()))))
 
Thanks
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @047 ,

 

Create a relationship between these two tables. Then create below measures.

country sales = CALCULATE(SUM(Sales[Total Sales]),FILTER(Sales,Sales[Country] = SELECTEDVALUE(Regions[Country])))

region sales = 
var _region = CALCULATE(MAX(Regions[Region]),FILTER(Regions,Regions[Country]=SELECTEDVALUE(Regions[Country])))
return
CALCULATE(SUM(Sales[Total Sales]),FILTER(ALL(Regions),Regions[Region] = _region))

subregion sales = 
var _subregion = CALCULATE(MAX(Regions[Subregion]),FILTER(Regions,Regions[Country]=SELECTEDVALUE(Regions[Country])))
return
CALCULATE(SUM(Sales[Total Sales]),FILTER(ALL(Regions),Regions[Subregion] = _subregion))

6.PNG

 

Best Regards,

Jay

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @047 ,

 

It's hard to provid DAX help without sample data. Please share some sample data and expected result to us.

 

Best Regards,

Jay

047
Frequent Visitor

Hi @Anonymous 

 

Here's a quick sample. these are the two tables:

 

Sales  Regions  
ProductCountryTotal SalesCountryRegionSubregion
AAustralia100AustraliaAPACOceania
AAustria200New ZealandAPACOceania
BNew Zealand100GermanyEURCentral Europe
CGermany400   
ABelgium300   

 

I have a slicer on Regions[Country] and a card visual which shows the avg value for a country, region and subregion. For example, If I select Australia on the slicer, I want the values to reflect for Australia, APAC & Oceania...something like this, but the country list should be populated based on the selected country from the slicer instead of hardcoding the values like the example below.

 

Subregion Sales = CALCULATE(AVERAGE('Sales'[Total Sales]), 'Sales'[Country] IN {"New Zealand", "Australia", "New Caledonia"})

 

I've tried my hand at it without luck...

 

temp =   
var FilteredCountryList = FILTER('Regions', Regions[Subregion] = FILTER(Regions, Regions[Country] = SELECTEDVALUE(Regions[Country])))
AvgRegion = calculate(AVERAGE('Sales'[total sales]),'Sales'[Country] in FilteredCountryList)))
 
Thanks
Anonymous
Not applicable

Hi @047 ,

 

Create a relationship between these two tables. Then create below measures.

country sales = CALCULATE(SUM(Sales[Total Sales]),FILTER(Sales,Sales[Country] = SELECTEDVALUE(Regions[Country])))

region sales = 
var _region = CALCULATE(MAX(Regions[Region]),FILTER(Regions,Regions[Country]=SELECTEDVALUE(Regions[Country])))
return
CALCULATE(SUM(Sales[Total Sales]),FILTER(ALL(Regions),Regions[Region] = _region))

subregion sales = 
var _subregion = CALCULATE(MAX(Regions[Subregion]),FILTER(Regions,Regions[Country]=SELECTEDVALUE(Regions[Country])))
return
CALCULATE(SUM(Sales[Total Sales]),FILTER(ALL(Regions),Regions[Subregion] = _subregion))

6.PNG

 

Best Regards,

Jay

047
Frequent Visitor

Indeed, it worked for me. I just had to add another another condition to clear the filter context on Sales, i.e. ALL(Sales).

Thanks for your help.

lbendlin
Super User
Super User

This is the standard "filtering up" pattern. Your measures need to calculate the parent entity(entities) and then modify the filter context accordingly.  It's a two (or more) step process best done with variables.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors