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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Hatterg
Regular Visitor

cross table query to find different grades for student

Greetings! I'd like some help with the following issue. 
We have three tables for storing students' grades across different moments. The three tables are the same, only the column "Period" has disctinctive data. The structure is similar to this: 

Captura de pantalla 2024-03-01 140105.png   Captura de pantalla 2024-03-01 140142.png  Captura de pantalla 2024-03-01 140155.png

So, when a student fails period A1, s/he has the opportunity at period A2, and later at A3. is there a way to trace the students with failed grades and generate a new column with the final grade after the three periods? this is just an example, the real data is 1.3 million rows of data.

Note, for us a grade of 5 equals a Failed subject

 

Your help will be greatly appreciated! 

 

1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

Hi @Hatterg 

 

@Greg_Deckler Very interesting idea!

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"PeriodA1"

vnuocmsft_0-1709516837659.png

 

"PeriodA2"

vnuocmsft_1-1709516899759.png

 

"PeriodA3"

vnuocmsft_2-1709516935247.png

 

Since your data is spread across three tables with similar structures, the first step is to merge these tables into one. This can be accomplished using Merge Query as New in Power Query.

 

vnuocmsft_3-1709517126339.png

 

Create a measure to calculation of final grades.

 

 

Final Grade = 
IF(
    SELECTEDVALUE(ConsolidatedGrades[PeriodA1]) > 5, 
    VALUES(ConsolidatedGrades[PeriodA1]), 
    IF(
        SELECTEDVALUE(ConsolidatedGrades[PeriodA2]) > 5, 
        VALUES(ConsolidatedGrades[PeriodA2]), 
        IF(
            SELECTEDVALUE(ConsolidatedGrades[PeriodA3]) > 5, 
            VALUES(ConsolidatedGrades[PeriodA3]), 
            BLANK()
        )
    )
)

 

 

Or you can create a calculated column.

 

 

Final Grades = 
IF(
    ConsolidatedGrades[PeriodA1] > 5, 
    ConsolidatedGrades[PeriodA1], 
    IF(
        ConsolidatedGrades[PeriodA2] > 5, 
       ConsolidatedGrades[PeriodA2], 
        IF(
            ConsolidatedGrades[PeriodA3] > 5, 
            ConsolidatedGrades[PeriodA3], 
            BLANK()
        )
    )
)

 

 

Here is the result.

 

vnuocmsft_4-1709517452111.png

 

Regards,

Nono Chen

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

4 REPLIES 4
v-nuoc-msft
Community Support
Community Support

Hi @Hatterg 

 

@Greg_Deckler Very interesting idea!

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"PeriodA1"

vnuocmsft_0-1709516837659.png

 

"PeriodA2"

vnuocmsft_1-1709516899759.png

 

"PeriodA3"

vnuocmsft_2-1709516935247.png

 

Since your data is spread across three tables with similar structures, the first step is to merge these tables into one. This can be accomplished using Merge Query as New in Power Query.

 

vnuocmsft_3-1709517126339.png

 

Create a measure to calculation of final grades.

 

 

Final Grade = 
IF(
    SELECTEDVALUE(ConsolidatedGrades[PeriodA1]) > 5, 
    VALUES(ConsolidatedGrades[PeriodA1]), 
    IF(
        SELECTEDVALUE(ConsolidatedGrades[PeriodA2]) > 5, 
        VALUES(ConsolidatedGrades[PeriodA2]), 
        IF(
            SELECTEDVALUE(ConsolidatedGrades[PeriodA3]) > 5, 
            VALUES(ConsolidatedGrades[PeriodA3]), 
            BLANK()
        )
    )
)

 

 

Or you can create a calculated column.

 

 

Final Grades = 
IF(
    ConsolidatedGrades[PeriodA1] > 5, 
    ConsolidatedGrades[PeriodA1], 
    IF(
        ConsolidatedGrades[PeriodA2] > 5, 
       ConsolidatedGrades[PeriodA2], 
        IF(
            ConsolidatedGrades[PeriodA3] > 5, 
            ConsolidatedGrades[PeriodA3], 
            BLANK()
        )
    )
)

 

 

Here is the result.

 

vnuocmsft_4-1709517452111.png

 

Regards,

Nono Chen

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

Greg_Deckler
Super User
Super User

@Hatterg Can you post that data as text so it can be copied and pasted into Enter data queries so that this can be mocked up? Also, is there any reason you can't combine those three tables into a single table using an Append query?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank's for your reply @Greg_Deckler . I can definitely append the tables, but after that I hit wall trying to obtain the final grade after the three periods thats why I thought about the possibility of a conditional column or something similar.

 

Sure, here is the data as text:

IdNameLast NameSubjectGradePeriod
1CarolDanversMath5A1
2Tony StarkMath9A1
3PeterParkerMath5A1
1CarolDanversLanguage6A1
2Tony StarkLanguage8A1
3PeterParkerLanguage5A1
1CarolDanversArt7A1
2Tony StarkArt9A1
3PeterParkerArt10A1
1CarolDanversScience5A1
2Tony StarkScience7A1
3PeterParkerScience9A1

 

IdNameLast NameSubjectGradePeriod
1CarolDanversMath8A2
3PeterParkerMath5A2
3PeterParkerLanguage9A2
1CarolDanversScience5A2

 

IdNameLast NameSubjectGradePeriod
3PeterParkerMath8A3
1CarolDanversScience6A3

Hi,

Based on the 3 tables that you have shared, show the expected result.


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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.