Showing results for 
Search instead for 
Did you mean: 
Deepak6642 Frequent Visitor
Frequent Visitor

Filter dataset based on rows belonging to all selected categories.

I am looking to do a Cohort analysis of students across multiple grades but the caveat being the students are the same in each grade.


For example, A class of 20 students graduates from Grade 1 to Grade 5 over 5 years. In this cohort, some students leave the class, and some new students join over the years.


I am struggling in finding score averages of students across 5 years of students who have attended all grades from 1 to 5.


Consider the following sample dataset


student_id, grade, score






1,2,100 //Graduate to grade 2




6,2,93 // New students joins, and student #5 leaves

1,3,100 Graduate to grade 3





7,3,87 // New student joins in grade 3


So my cohort should only consider student nos 1 through 4

 while doing averages, count of students across grades etc.


Can you advise?

Community Support Team
Community Support Team

Re: Filter dataset based on rows belonging to all selected categories.

Hi @Deepak6642,


Based on my test, we can take the following steps to meet your requirement.


1. Enter the data and create a calculated table using the formula. Then create relationship between tables based on the student_id.


Table = 
    UNION (
        SELECTCOLUMNS ( '1', "new", '1'[student_id] ),
        SELECTCOLUMNS ( '2', "new", '2'[student_id] ),
        SELECTCOLUMNS ( '3', "new", '3'[student_id] )

2. Create the measures as below. And create a table visual and make that filterd by Measure.


Measure = IF(MAX('1'[grade]) = BLANK() || MAX('2'[grade])=BLANK() || MAX('3'[grade])= BLANK(), BLANK(),1)
ave 1 = SUMX(ALLSELECTED('1'),'1'[score])/[count]
ave 2 = SUMX(ALLSELECTED('2'),'2'[score])/[count]
ave 3 = SUMX(ALLSELECTED('3'),'3'[score])/[count]
count = CALCULATE(COUNT('Table'[new]),ALLSELECTED('Table'))



For more details, please check the pbix as attached. If it doesn't meet your requirement, kindly share your excepted result to me.




Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Deepak6642 Frequent Visitor
Frequent Visitor

Re: Filter dataset based on rows belonging to all selected categories.

Thank you for the attempt @v-frfei-msft.


However, this is not close to the expected result. The data for the various grades comes from a single table instead of different tables, as listed in the original message.


The dashboard must allow the user to choose a start and end grade, which ought to filter the results and present the same student cohort data as an aggregate.


The resultant graph/table must show the aggregate value across only the students which exist in all the grades from the chosen grade.




Above you can see the plot of aggregates of scores for a subject across the grades. The score aggregate is for students who are the same across all grades over the years. It excludes students who joined in or left in the middle for the selected grade/period.



Helpful resources

Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Users Online
Currently online: 21 members 812 guests
Please welcome our newest community members: