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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
osaamashehzad
Frequent Visitor

How to calculate conditional average by aggregating rows mapped to each participant?

I am doing a survey analysis in which each participant is identified by a unique identifier called "ID". The table contains the following cols: 

  1. Question: describes the question asked
  2. Category: describes the category that questions are mapped
  3. Score: the rating that respondent gave from 1 to 5 

What I want to do is create 2 new columns: "Wellbeing Average" and "is Favorable" for each participant ID. The first metric is supposed to calculate the average of scores received in all questions per participant that are have category = "wellbeing". The second metric is basically a condition which should return TRUE if the average is >= 4, else FALSE. For example, the output should look like this

Desired Output: 

osaamashehzad_1-1701259290915.png

 

 

Below is the snapshot of table

osaamashehzad_0-1701259243420.png

 

by the way, Tableau has a very straightforward calc for this i.e. 

 

 

{FIXED ID: AVERAGE (IF CATEGORY = "Wellbeing" THEN SCORE RETURN)} 

 

 

but a similar version in PowerBI is unbelievingly confusing to find! please help so I can learn this. 

 

1 ACCEPTED SOLUTION
Aibloy
New Member

Hi  , 
In PowerBI you have a function that is call CALCULATE.With this function you can modify the context in which a expression is evaluated,

In your scenario, you want to evaluate the expression "Average":

 

 

Average_Wellbeing = AVERAGE('Table'[Score]) 

 

 

 

But, you want to evaluate this expression in a certain context, so, with CALCULATE:

 

 

 CALCULATE(AVERAGE('Table'[Score]),'Table'[Category]="Wellbeing") 

 

 

Replacing 'Table' by your Table Name.

Hope it helps!

 

 

 

 

 

@osaamashehzad

View solution in original post

2 REPLIES 2
osaamashehzad
Frequent Visitor

yes this helps! thank you so much. 

Aibloy
New Member

Hi  , 
In PowerBI you have a function that is call CALCULATE.With this function you can modify the context in which a expression is evaluated,

In your scenario, you want to evaluate the expression "Average":

 

 

Average_Wellbeing = AVERAGE('Table'[Score]) 

 

 

 

But, you want to evaluate this expression in a certain context, so, with CALCULATE:

 

 

 CALCULATE(AVERAGE('Table'[Score]),'Table'[Category]="Wellbeing") 

 

 

Replacing 'Table' by your Table Name.

Hope it helps!

 

 

 

 

 

@osaamashehzad

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.