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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
JDLee23
Helper I
Helper I

Calculate an average based on an implicit filter by a second column

Hi,

 

I am trying to create a measure which will allow me to show an average, based on the selection in a slicer. However, the slicer only implicitly selects the group of data, for example -

 

In a table of Country, City, TotalSales, I want to show have a measure of the average TotalSales for both a selected city and the country which that city is in (to allow for easy comparison). However, the country is not explicitly selected anywhere, and as such BI seems to be unable to calculate the average...?

 

E.g. by selecting 'London', one card will show the average total for London, whilst the other card now shows the average for England.

 

Please note that these are in separate cards for presentation reasons, not a single table!

 

I seem to get somewhere with GROUPBY() and SUMMARIZE(), but my experience of DAX is too limited to fully understand how to do this.

 

Any help would be much appreciated, thank you in advance!

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @JDLee23,

 

Thanks for @TomMartens's suggestion, it works fine in my test. But, it is not able to directly define a column name for variable, so, I made some modification:

Avg Sales Country = 
var currentCountry = LASTNONBLANK('table'[Country],1)
return
CALCULATE(
    AVERAGE('table'[TotSales])
    ,ALL('table'[City])
    ,'table'[Country] = currentCountry
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @JDLee23,

 

Thanks for @TomMartens's suggestion, it works fine in my test. But, it is not able to directly define a column name for variable, so, I made some modification:

Avg Sales Country = 
var currentCountry = LASTNONBLANK('table'[Country],1)
return
CALCULATE(
    AVERAGE('table'[TotSales])
    ,ALL('table'[City])
    ,'table'[Country] = currentCountry
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey @v-yulgu-msft,

 

silly me, thanks for the adjustment.

 

Regards

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@v-yulgu-msft@TomMartens - thanks very much for your help, much appreciated!

TomMartens
Super User
Super User

Hey,

 

If there is a slicer that selects the city, these measures should work

Avg Sales City = 
CALCULATE(
  AVERAGE('table'[TotSales])
)

and

Avg Sales Country = 
var currentCountry = 'table'[Country]
return
CALCULATE(
    AVERAGE('table'[TotSales])
    ,ALL('table'[City])
    ,'table'[Country] = currentCountry
)

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors