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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
chatals
New Member

DAX - Calculate average for rows not included in slicer selections

I'm working on a clinical trials study. I have a column "Symptom Progression Rate (SPR)" which is a numeric value that describes the speed at which an illness is progressing. For study participants, I'm trying to compare an average of that value, when filtered by a one or more demographic slicers such as gender, age, and ethnicity as well as clinical slicers that includes medications and nutrients, to the average SPR for participants who are not included in the slicer selections.

 

For example, out of 1,500 study participants, if I select 400 male participants between the age of 40-50 that are taking a particular drug, I want to calculate the average SPR for the 1,100 that are not selected by any of the slicers.

 

Model

 

DIM
Participant Table
-Participant ID
-Age
-Gender
-Ethnicity

 

(1:1)

Slope Table
-Participant ID
-SPR

 

(1:Many)
Drug Table
-ParticipantID
-Name of Drug

 

(1:Many)
Nutrient Table
-Participant ID
-Nutrient Name

1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

Hi @chatals 

 

For your question, here is the method I provided:

 

“Participants”

vnuocmsft_0-1731380266302.png

“Slope”

vnuocmsft_1-1731380303031.png

“Drugs”

 

vnuocmsft_2-1731380353801.png

“Nutrients”

vnuocmsft_3-1731380379802.png

 

I suggest that you modify the relationship between them as follows:

 

vnuocmsft_5-1731380596108.png

 

Enter the power query interface to merge a new table for multiple slicers:

 

vnuocmsft_6-1731380692539.png

 

Don't create any relationships.

 

vnuocmsft_7-1731380722117.png

 

Create measures.

 

Average_SPR_Filtered = 
var _minage = MIN('Merge Table'[Age])
var _maxage = MAX('Merge Table'[Age])
var _gender = SELECTEDVALUE('Merge Table'[Gender])
var _ethnicity = SELECTEDVALUE('Merge Table'[Ethnicity])
var _drug = SELECTEDVALUE('Merge Table'[Drugs.Name of Drug])
RETURN
AVERAGEX(
    FILTER(
        'Participants',
        'Participants'[Gender] = _gender 
        &&
        'Participants'[Age] >= _minage && 'Participants'[Age] <= _maxage 
        &&
        'Participants'[Ethnicity] = _ethnicity
        &&
        RELATED('Drugs'[Name of Drug]) = _drug
    ),
    RELATED(Slope[SPR])
)

 

Average_SPR_Non_Filtered = 
var _minage = MIN('Merge Table'[Age])
var _maxage = MAX('Merge Table'[Age])
var _gender = SELECTEDVALUE('Merge Table'[Gender])
var _ethnicity = SELECTEDVALUE('Merge Table'[Ethnicity])
var _drug = SELECTEDVALUE('Merge Table'[Drugs.Name of Drug])
RETURN
AVERAGEX(
    FILTER(
        'Participants',     
        'Participants'[Gender] = _gender 
        &&
        ('Participants'[Age] < _minage || 'Participants'[Age] > _maxage)
        &&
        'Participants'[Ethnicity] <> _ethnicity
        &&
        RELATED('Drugs'[Name of Drug]) <> _drug   
        
    ),
    RELATED(Slope[SPR])
)

 

Here is the result.

 

vnuocmsft_8-1731380945811.png

 

Regards,

Nono Chen

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

1 REPLY 1
v-nuoc-msft
Community Support
Community Support

Hi @chatals 

 

For your question, here is the method I provided:

 

“Participants”

vnuocmsft_0-1731380266302.png

“Slope”

vnuocmsft_1-1731380303031.png

“Drugs”

 

vnuocmsft_2-1731380353801.png

“Nutrients”

vnuocmsft_3-1731380379802.png

 

I suggest that you modify the relationship between them as follows:

 

vnuocmsft_5-1731380596108.png

 

Enter the power query interface to merge a new table for multiple slicers:

 

vnuocmsft_6-1731380692539.png

 

Don't create any relationships.

 

vnuocmsft_7-1731380722117.png

 

Create measures.

 

Average_SPR_Filtered = 
var _minage = MIN('Merge Table'[Age])
var _maxage = MAX('Merge Table'[Age])
var _gender = SELECTEDVALUE('Merge Table'[Gender])
var _ethnicity = SELECTEDVALUE('Merge Table'[Ethnicity])
var _drug = SELECTEDVALUE('Merge Table'[Drugs.Name of Drug])
RETURN
AVERAGEX(
    FILTER(
        'Participants',
        'Participants'[Gender] = _gender 
        &&
        'Participants'[Age] >= _minage && 'Participants'[Age] <= _maxage 
        &&
        'Participants'[Ethnicity] = _ethnicity
        &&
        RELATED('Drugs'[Name of Drug]) = _drug
    ),
    RELATED(Slope[SPR])
)

 

Average_SPR_Non_Filtered = 
var _minage = MIN('Merge Table'[Age])
var _maxage = MAX('Merge Table'[Age])
var _gender = SELECTEDVALUE('Merge Table'[Gender])
var _ethnicity = SELECTEDVALUE('Merge Table'[Ethnicity])
var _drug = SELECTEDVALUE('Merge Table'[Drugs.Name of Drug])
RETURN
AVERAGEX(
    FILTER(
        'Participants',     
        'Participants'[Gender] = _gender 
        &&
        ('Participants'[Age] < _minage || 'Participants'[Age] > _maxage)
        &&
        'Participants'[Ethnicity] <> _ethnicity
        &&
        RELATED('Drugs'[Name of Drug]) <> _drug   
        
    ),
    RELATED(Slope[SPR])
)

 

Here is the result.

 

vnuocmsft_8-1731380945811.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.