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
Anonymous
Not applicable

Getting the max for every student for each Month

Greeting lovely memebers , 

 

let's say i have a table where it contains the list of the student , their mark for each subject and the month number .

 

im trying to create a calculated column ( exemple : Max_value column in the picture below)

 

this column will contain the max mark for every student in every month .

i was able to get the max value for each student but i cant get the max for each month aswell .

 

Below is my output , as you can see Max_value column is what im trying to acheive. Thanks all in advance 

 

Rfrikha1992_0-1631547377402.png

 

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

Hi @Anonymous ,

 

Please follow these steps:

 

1. Add a Index column:

Eyelyn9_0-1631777559116.png

 

2. Use RANKX() to rank by Mark based on each Month Number and Student ID:

Rank by Mark =
RANKX (
    FILTER (
        'Table',
        [Month Number] = EARLIER ( 'Table'[Month Number] )
            && [Student ID] = EARLIER ( 'Table'[Student ID] )
    ),
    [Mark],
    ,
    DESC,
    DENSE
)

3. Use RANKX() again to rank based on the Rank column and Index column:

Max_Value =
VAR _rank2 =
    RANKX (
        FILTER (
            'Table',
            [Month Number] = EARLIER ( 'Table'[Month Number] )
                && [Student ID] = EARLIER ( 'Table'[Student ID] )
        ),
        [Rank by Mark] * 10 + [Index],
        ,
        ASC,
        DENSE
    )
RETURN
    IF ( _rank2 = 1, [Mark], BLANK () )

Here is the final output:

Eyelyn9_1-1631777637650.png

 

Best Regards,
Eyelyn Qin
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
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please follow these steps:

 

1. Add a Index column:

Eyelyn9_0-1631777559116.png

 

2. Use RANKX() to rank by Mark based on each Month Number and Student ID:

Rank by Mark =
RANKX (
    FILTER (
        'Table',
        [Month Number] = EARLIER ( 'Table'[Month Number] )
            && [Student ID] = EARLIER ( 'Table'[Student ID] )
    ),
    [Mark],
    ,
    DESC,
    DENSE
)

3. Use RANKX() again to rank based on the Rank column and Index column:

Max_Value =
VAR _rank2 =
    RANKX (
        FILTER (
            'Table',
            [Month Number] = EARLIER ( 'Table'[Month Number] )
                && [Student ID] = EARLIER ( 'Table'[Student ID] )
        ),
        [Rank by Mark] * 10 + [Index],
        ,
        ASC,
        DENSE
    )
RETURN
    IF ( _rank2 = 1, [Mark], BLANK () )

Here is the final output:

Eyelyn9_1-1631777637650.png

 

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

Anonymous
Not applicable

Works perfectly ! Thanks 

ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous - Not exactly the output you are looking for but the calculations are correct.

Max_Value = 
VAR student = TableName[Student ID]
VAR monthNum = TableName[Month Number]
VAR Result =
CALCULATE(
    MAX(TableName[Mark]),
    FILTER(
        TableName,
        TableName[Student ID] = student
    ),
    KEEPFILTERS(TableName[Month Number] = monthNum)
)
Return 
    Result
Month Max_Value = 
VAR monthNum = TableName[Month Number]
VAR Result =
CALCULATE(
    MAX(TableName[Mark]),
    FILTER(
        TableName,
        TableName[Month Number] = monthNum
    )
)
Return 
    Result

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

unfortuanately not the output that im looking for .

 

what i need is for each month the hight rank for each student as it shows in the picture above.

 

@Anonymous - Seems I can't get your expected result. The closest I could get is below:

Max_Value = 
VAR student = TableName[Student ID]
VAR monthNum = TableName[Month Number]
VAR Result =
CALCULATE(
    MAX(TableName[Mark]),
    FILTER(
        TableName,
        TableName[Student ID] = student
    ),
    KEEPFILTERS(TableName[Month Number] = monthNum)
)
Return 
    CALCULATE(
        MAX(TableName[Mark]),
        FILTER(
            ALLEXCEPT(TableName,TableName[Mark]),
            TableName[Mark] = Result
        )
    )

image.png

Hopefully someone else can show us both how to get your desired result.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



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.