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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
yuvalpi
Helper I
Helper I

getting a value in a column based on values of few other columns

Hi,

I have a problem that I cannot resolve.

 

here is my table:

 

DateStudent NameSubjectTest Result
08-Dec-23Amir A.Math80
10-Dec-23Amir A.Math90
05-Nov-23Baruch B.History70
01-Dec-23Amir A.Science65
01-Oct-23Baruch B.Math92
1-Sep-23Baruch B.Math85

 

I would like to have a column that indicates the last "Test Result" based on the Student Name and Subject.

for Amir A. - Math - I would like to get 90, because the test was done on Dec, 10th

for Baruch B. - Math - I would like to get  92

for Baruch B. - History - I would like to see 70

 

is this possible using a DAX in a column?

 

it's OK to get the number 90 for all rows of Amir A. , Math.

 

Thank you in advance,

Yuval

2 ACCEPTED SOLUTIONS
Bibiano_Geraldo
Super User
Super User

Create a new column and paste the following expression:
Note: Make sure to change 'Sheet1' to your table name.

Column =
VAR student = Sheet1[Student Name]
VAR subject = Sheet1[Subject]
VAR myDate =
CALCULATE(
    LASTDATE(
        Sheet1[Date]
    ),
    FILTER(
        Sheet1,
        Sheet1[Student Name] = student &&
        Sheet1[Subject] = subject
    )
)
VAR lastTestResult =
CALCULATE(
    MAX(
        Sheet1[Test Result]
    ),
    FILTER(
        Sheet1,
        Sheet1[Student Name] = student &&
        Sheet1[Subject] = subject &&
        Sheet1[Date] = myDate
    )
)
RETURN
lastTestResult

Explanations:
  1. Variable Declarations:
    • VAR student = Sheet1[Student Name]: Stores the student's name from the "Student Name" column.
    • VAR subject = Sheet1[Subject]: Stores the subject from the "Subject" column.
    • VAR myDate = ...: Calculates the latest date for the specific student and subject using CALCULATE and LASTDATE.
    • VAR lastTestResult = CALCULATE(MAX(Sheet1[Test Result]), ...): Calculates the maximum test result for the specific student, subject, and the latest date.
  2. Return the Result:
    • RETURN lastTestResult: Returns the result stored in the lastTestResult variable as the final output of the DAX expression.

View solution in original post

smpa01
Community Champion
Community Champion

@yuvalpi  you can also do this

Measure = 
VAR _grouping =
    ALLEXCEPT ( 'Table 1', 'Table 1'[Student Name], 'Table 1'[Subject] ) //define GROUPBY columns here 
VAR one =
    CALCULATE ( MAX ( 'Table 1'[Date] ), _grouping ) // what is the max date by the above group
VAR two =
    CALCULATE ( MAX ( 'Table 1'[Test Result] ), _grouping, 'Table 1'[Date] = one ) //what is the test result on max date partioned by grouping
RETURN
    two

 

smpa01_0-1701960853912.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

View solution in original post

4 REPLIES 4
smpa01
Community Champion
Community Champion

@yuvalpi  you can also do this

Measure = 
VAR _grouping =
    ALLEXCEPT ( 'Table 1', 'Table 1'[Student Name], 'Table 1'[Subject] ) //define GROUPBY columns here 
VAR one =
    CALCULATE ( MAX ( 'Table 1'[Date] ), _grouping ) // what is the max date by the above group
VAR two =
    CALCULATE ( MAX ( 'Table 1'[Test Result] ), _grouping, 'Table 1'[Date] = one ) //what is the test result on max date partioned by grouping
RETURN
    two

 

smpa01_0-1701960853912.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

Hi smpa01,

I tried your solution and it also works great!

much appreciated!

 

thank you,

Yuval

 

 

yuvalpi
Helper I
Helper I

Hi Bibiano_Geraldo,

This is amazing!! thank you so much for you quick and proffessional help!

 

much appreciated,

Yuval

Bibiano_Geraldo
Super User
Super User

Create a new column and paste the following expression:
Note: Make sure to change 'Sheet1' to your table name.

Column =
VAR student = Sheet1[Student Name]
VAR subject = Sheet1[Subject]
VAR myDate =
CALCULATE(
    LASTDATE(
        Sheet1[Date]
    ),
    FILTER(
        Sheet1,
        Sheet1[Student Name] = student &&
        Sheet1[Subject] = subject
    )
)
VAR lastTestResult =
CALCULATE(
    MAX(
        Sheet1[Test Result]
    ),
    FILTER(
        Sheet1,
        Sheet1[Student Name] = student &&
        Sheet1[Subject] = subject &&
        Sheet1[Date] = myDate
    )
)
RETURN
lastTestResult

Explanations:
  1. Variable Declarations:
    • VAR student = Sheet1[Student Name]: Stores the student's name from the "Student Name" column.
    • VAR subject = Sheet1[Subject]: Stores the subject from the "Subject" column.
    • VAR myDate = ...: Calculates the latest date for the specific student and subject using CALCULATE and LASTDATE.
    • VAR lastTestResult = CALCULATE(MAX(Sheet1[Test Result]), ...): Calculates the maximum test result for the specific student, subject, and the latest date.
  2. Return the Result:
    • RETURN lastTestResult: Returns the result stored in the lastTestResult variable as the final output of the DAX expression.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.