cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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:

Below is the snapshot of table

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
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!

2 REPLIES 2
Frequent Visitor

yes this helps! thank you so much.

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!

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.