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

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

Reply
KabirDhupelia
Regular Visitor

Using a slicer and a filtered DAX measure

Hello, I've got an issue with filtering on selected values. 

In a simplistic dataset (below):

BreedSpeciesLife expectancyPredominant colour

LabradorDog10White
German SherphardDog12Brown
PekingeseDog15White
Border CollieDog11Black
Scottish FoldCat16Orange
Turkish AngoraCat17White
SiameseCat15Beige
MaincoonCat18Brown
ParrotBird90Orange
PigeonBird4Grey
WeaverBird2Yellow
EagleBird17Grey


I am trying to have a measure that works with a slicer to show me the average age of a species. The goal is to be able to compare various other attributes to that average. I've created a measure that looks like this:

Species life expentancy =
var Species_Selected = SELECTEDVALUE('Life expectancies'[Species])
var Years_ = CALCULATE(SUM('Life expectancies'[Life expectancy]),ALL('Life expectancies'),'Life expectancies'[Species]=Species_Selected)
var NumBreeds_ = CALCULATE(DISTINCTCOUNT('Life expectancies'[Breed]),ALL('Life expectancies'),'Life expectancies'[Species]=Species_Selected)
Return DIVIDE(Years_,NumBreeds_)
 
But when I use a slicer to select the species, it only works correctly on one selection. The moment I select more than 1 species (Cat and Dog), I get a blank. What I'd like to happen when selecting multiple species is for it to sum the species life expentancies and divide that sum by the distinct number of breeds in the selected species to give an average. 

This is a dummy dataset, so picture this problem with 3 000 000 rows of info.
 
Thanks!
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @KabirDhupelia ,

 

When you use the SELECTEDVALUE it only returns a single value so when you select more than one you get the blank. Try the following measure:

Species life expentancy =

var Years_ = CALCULATE(SUM('Life expectancies'[Life expectancy]),ALLSELECTED('Life expectancies'[Species])
var NumBreeds_ = CALCULATE(DISTINCTCOUNT('Life expectancies'[Breed]),ALLSELECTED('Life expectancies'[Species])
Return DIVIDE(Years_,NumBreeds_)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @KabirDhupelia ,

 

When you use the SELECTEDVALUE it only returns a single value so when you select more than one you get the blank. Try the following measure:

Species life expentancy =

var Years_ = CALCULATE(SUM('Life expectancies'[Life expectancy]),ALLSELECTED('Life expectancies'[Species])
var NumBreeds_ = CALCULATE(DISTINCTCOUNT('Life expectancies'[Breed]),ALLSELECTED('Life expectancies'[Species])
Return DIVIDE(Years_,NumBreeds_)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks! Works like a charm, going to move this over to the mega dataset but I can't see why it wouldn't work if it worked on the dummy set. Thanks again

Helpful resources

Announcements
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