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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.