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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
en2000
Frequent Visitor

Calculate Average for Subset of Cohort

Hey All,

I'm fairly new to PowerBI, so I'm doing my best to challenge myself in order to learn more.

 

I'm building a dashboard to display data for an individual student who has been selected from a slicer.  On the dashboard, is a bar chart that sums a particular value for the student for each year they have attended the school. 

 

en2000_1-1712182565702.png

 

 

Currently, if I understand correctly, the blue line is the average of all students for the year.  However, I want the blue line to represent the average for the selected students year level for each year.  I assume I need to create this in a measure, but I'm not sure where to start.  Any pointers would be great.  Cheers, E.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @en2000 ,

First of all, many thanks to @Ashish_Mathur  for your very quick and effective replies, and I will give some additions below:

1.Create the sample table.

vjiewumsft_0-1712217448285.png

2.Create the measure to calculate average for the selected student.

 

Selected_student_avg = 
var stu = SELECTEDVALUE('Table'[Student])
VAR sco = CALCULATE(SUM('Table'[Score]), FILTER(ALLEXCEPT('Table', 'Table'[Year]), 'Table'[Student] = stu))
var stu_year = CALCULATE(SUM('Table'[Score]), FILTER(ALLEXCEPT('Table', 'Table'[Year]), MIN('Table'[Year])))
RETURN
DIVIDE(sco, stu_year)

 

3.Select the slicer visual and drag the student into the visual.

vjiewumsft_1-1712217494635.png

4.Drag the Year into the X-axis. Drag the score into the column y-axis. Drag the measure into the Line y-axis.

vjiewumsft_2-1712217501807.png

5.Select the student in the slicer. The result is shown below.

vjiewumsft_3-1712217508907.png

Best Regards,

Wisdom Wu

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

5 REPLIES 5
en2000
Frequent Visitor

Thanks @Anonymous for your detailed and helpful reply.  I have been working on other priorities since I posted this question, so haven't had a chance to see if it works for my use case, but it looks very promising.  

Anonymous
Not applicable

Hi @en2000 ,

If the method above works, please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Wisdom Wu

Anonymous
Not applicable

Hi @en2000 ,

First of all, many thanks to @Ashish_Mathur  for your very quick and effective replies, and I will give some additions below:

1.Create the sample table.

vjiewumsft_0-1712217448285.png

2.Create the measure to calculate average for the selected student.

 

Selected_student_avg = 
var stu = SELECTEDVALUE('Table'[Student])
VAR sco = CALCULATE(SUM('Table'[Score]), FILTER(ALLEXCEPT('Table', 'Table'[Year]), 'Table'[Student] = stu))
var stu_year = CALCULATE(SUM('Table'[Score]), FILTER(ALLEXCEPT('Table', 'Table'[Year]), MIN('Table'[Year])))
RETURN
DIVIDE(sco, stu_year)

 

3.Select the slicer visual and drag the student into the visual.

vjiewumsft_1-1712217494635.png

4.Drag the Year into the X-axis. Drag the score into the column y-axis. Drag the measure into the Line y-axis.

vjiewumsft_2-1712217501807.png

5.Select the student in the slicer. The result is shown below.

vjiewumsft_3-1712217508907.png

Best Regards,

Wisdom Wu

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

en2000
Frequent Visitor

If I'm calculating the average per year level, per year, then the blue line would NOT be straight as the average could change.

 

The file has personal data, so I unfortunately cannot share.

Ashish_Mathur
Super User
Super User

Hi,

Should the blue line be a straight line then?  If my understanding is correct, then share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.