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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
duesouth
Helper I
Helper I

Relationships in a Model

I've been working on a model this year, which has grown.  We're finding some filters don't work as expected and I believe this to be because of issues with relationships.

 

My main table is the pupil data table.  An example is:

External IDPupil NameGenderYearRegEthnicityFirst LanguageSENG&TEALIn CareFSM Ever 6Pupil Premium Indicator
1OneM88R7White - BritishGerman YesYesFFF
2TwoF88R9White - BritishEnglishK NoFFF
3ThreeF88R7White - BritishEnglish  NoFFF

 

From different areas and therefore reports from our school MIS, we have 2 tables for looking at their KS2 levels and CAT Tests.

 

KS2

External IDGPVS Scaled ScoreReading Scaled ScoreMaths Scaled Score
1838287
2108111108
3929790

 

CATS

External IDCAT Verbal SASCAT Quantitative SASCAT Non Verbal SASCAT Spatial SASCAT Mean SAS
1108113937096
21199610599105
3108869810599

 

If I create a relationship in Power BI - to the pupil table - both are 1:1 relationships.  Is it better to merge the data so all is within the pupil table?

 

Next, there's the classes table.  Each pupil has multiple subjects/classes (I've just put 3 below for this example).  I'm finding if I link Pupil Data Table\External ID with Classes\External ID, Power BI creates a One to Many relationship which has a single cross-filter direction.  At this point if I try to filter by class on KS2 or CAT Tests with simple cards for the average of each field in the each table, the cards don't change on each filter.  If I change the cross-filter direction to both - that does work - but from what I've watched on YouTube/read, this may not be the way forward...

External IdClassTeacherSubject
18w/En3A EnglishEnglish
18w/Ma2A MathsMathematics
18w/ScBA ScienceScience
28xy/En1B EnglishEnglish
28xy/Ma1C MathsMathematics
28xy/ScAC ScienceScience
38xy/En1C EnglishEnglish
38xy/Ma2C MathsMathematics
38xy/ScCC ScienceScience

After that, we also have their report grades.  Again, each pupil has multiple grades - one for each subject and looks something like this:

External IdYearResultResult dateResultsetAspect NameSubject
1Year 8401/12/2023Year  8 AutumnSC KS3 Mastery ScScience
1Year 8728/11/2023Year  8 AutumnSC KS3 Mastery MaMathematics
1Year 8616/11/2023Year  8 AutumnSC KS3 Mastery EnEnglish
2Year 8601/12/2023Year  8 AutumnSC KS3 Mastery ScScience
2Year 8928/11/2023Year  8 AutumnSC KS3 Mastery MaMathematics
2Year 8316/11/2023Year  8 AutumnSC KS3 Mastery EnEnglish
3Year 8401/12/2023Year  8 AutumnSC KS3 Mastery ScScience
3Year 8228/11/2023Year  8 AutumnSC KS3 Mastery MaMathematics
3Year 8416/11/2023Year  8 AutumnSC KS3 Mastery EnEnglish

 

What would be the best practice in terms of relationships - type and cross-filter direction to create an efficient model where we can filter by class against KS2, CAT Test and report levels?  We've got other stuff linking in - but breaking it down I think my issues are from these key tables and I'd really appreciate your knowledge.  I worked on MS Access many years ago - and while I understand basically about relationships, in practice with a Power BI model which has grown, I don't believe it's optimal...

1 ACCEPTED SOLUTION
Thejeswar
Super User
Super User

Hi @duesouth ,

As far as I checked based on what I understood, I can see the relationship between these tables are working fine. There is something else in your case which is not working as expected.

 

I did the following before testing this

1. Merged the pupil, ks2 and cats table into 1 table.

2. Joined classes with the master table based on external id.

3. Created cards showing average values for Ks2 and cats column.

 

The Below is the screenshot. I think it is working fine for the filter applied on classes table

1. I have clicked on the first row. The Cards match with the value in the table

Thejeswar_0-1729606970164.png

 

2. I am doing filtering of classes in a slicer and I see the results are wrong. This is because when a slicer is applied, it is applied separately on the classes table. In your case, the relation flows from pupil to classes and not the otherway around. Hence any filter that you are applying on the classes table won't impact pupil table.

 

The Solution I can see in this case is both as cross filter direction.

 

Alternate Solution to Bidirectional Filters:

But if you are not willing to use it, try having one more separate table for classes and set classes to filter pupil. Use USERELATIONSHIP() to activate this in your measures as required.

 

The Below screenshot shows the data model post introducing the duplicate table for classes.

Thejeswar_1-1729608143885.png

 

Coming to the UI, you need to use the slicer for classes from the dup_classes table. Since you are having the relation to the main classes table, this slicer will also filter the classes table. USERELATIONSHIP() will filter the pupil table. 

 

To leverage the USERELATIONSHIP(), create new measures for your values. Few are given below

ACATSAS = CALCULATE(AVERAGE(pupil[CAT Mean SAS]), USERELATIONSHIP(dup_classes[External Id], pupil[External ID]))
AGPVSScaled = CALCULATE(AVERAGE(pupil[GPVS Scaled Score]), USERELATIONSHIP(dup_classes[External Id], pupil[External ID]))

 

The Output will look like shown below

Thejeswar_2-1729608337512.png

 

If this helps, Kindly mark this as a Solution. would appreciate a Kudo from you!! 

 

Regards,

View solution in original post

4 REPLIES 4
Thejeswar
Super User
Super User

Hi @duesouth ,

As far as I checked based on what I understood, I can see the relationship between these tables are working fine. There is something else in your case which is not working as expected.

 

I did the following before testing this

1. Merged the pupil, ks2 and cats table into 1 table.

2. Joined classes with the master table based on external id.

3. Created cards showing average values for Ks2 and cats column.

 

The Below is the screenshot. I think it is working fine for the filter applied on classes table

1. I have clicked on the first row. The Cards match with the value in the table

Thejeswar_0-1729606970164.png

 

2. I am doing filtering of classes in a slicer and I see the results are wrong. This is because when a slicer is applied, it is applied separately on the classes table. In your case, the relation flows from pupil to classes and not the otherway around. Hence any filter that you are applying on the classes table won't impact pupil table.

 

The Solution I can see in this case is both as cross filter direction.

 

Alternate Solution to Bidirectional Filters:

But if you are not willing to use it, try having one more separate table for classes and set classes to filter pupil. Use USERELATIONSHIP() to activate this in your measures as required.

 

The Below screenshot shows the data model post introducing the duplicate table for classes.

Thejeswar_1-1729608143885.png

 

Coming to the UI, you need to use the slicer for classes from the dup_classes table. Since you are having the relation to the main classes table, this slicer will also filter the classes table. USERELATIONSHIP() will filter the pupil table. 

 

To leverage the USERELATIONSHIP(), create new measures for your values. Few are given below

ACATSAS = CALCULATE(AVERAGE(pupil[CAT Mean SAS]), USERELATIONSHIP(dup_classes[External Id], pupil[External ID]))
AGPVSScaled = CALCULATE(AVERAGE(pupil[GPVS Scaled Score]), USERELATIONSHIP(dup_classes[External Id], pupil[External ID]))

 

The Output will look like shown below

Thejeswar_2-1729608337512.png

 

If this helps, Kindly mark this as a Solution. would appreciate a Kudo from you!! 

 

Regards,

Thanks for taking the time to look at this - and the very detailed response.  Much appreciated!

Rupak_bi
Super User
Super User

Hi, Power BI by default creates best optimum relationships. Dont worry about that.tables having unique values will work as dimention tables and with multiple values as fact tables. for cross filtering, you need to twek the modelling part. let me know what issue you are facing. 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Thanks for the reply.  The main problem with the model is when I want to filter by class on a page.  I've got a screen with basic cards for averages for KS2 and CATS - but have been finding if you click on a class, the cards don't change.  I've got the relationships as below as Power BI has created (the KS4 WAG 2023 2024 table is basically the results table I talked about in my original post).  To make it work, I've put the Pupil Data/Classes with Pupils relationship as both way - but when we've added to the model, it hasn't been giving us expected results - so I think I need to get this basic bit right first...

 

Relationships.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.