Forum Discussion
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:
- Question: describes the question asked
- Category: describes the category that questions are mapped
- 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.
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
- AibloyRegular Visitor
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! - osaamashehzadFrequent Visitor
yes this helps! thank you so much.