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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Hatterg
New Member

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?


@ 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!:
The Definitive Guide to Power Query (M)

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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