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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX help to calculate current year and previous year score bases on the max date of each project id.

Hello experts,
I want to create a calculated column for current year and previous year score bases on the max date of each project id.

Please help

Input Table

Project IDDateScoreCategory   
101-01-202415A   
105-05-20245B   
107-07-2023100A   
109-09-202330A   
201-01-2024150A   
202-02-2023 A   
301-01-202470A   
302-02-202390B   



Output Table

Project IDCategoryCurrent Year Max ScorePrevious Year Max Score  
1A1530  
1B5   
2B150   
3A70   
3B 90  
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

 

You can modify the formula to the following:

 

Previous Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), YEAR([Date]) = YEAR(TODAY()) - 1))
RETURN
CALCULATE(MAX([Score]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), [Date] = _maxDate))

 

Current Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), YEAR([Date]) = YEAR(TODAY())))
RETURN
CALCULATE(MAX([Score]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), [Date] = _maxDate))

 

Output:

vxuxinyimsft_0-1718873128626.png

 

Best Regards,
Yulia Xu

 

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

Thank you @Anonymous for the quick help.
But below formula is giving wrong output, getting current year score in previous year formula.
Also I need to consider category also in the formula to identify unique records.
Please help @Anonymous 

Previous Year Max Score =
VAR _maxDate = CALCULATE(MAX(Table[Date]),
FILTER(ALLEXCEPT('Table', 'Table'[ID],Table[Category]),
YEAR(Table[Date]) = YEAR(TODAY()) - 1))
RETURN
CALCULATE(MAX(Table[Score]), FILTER('Table', Table[Date] = _maxDate))
Anonymous
Not applicable

Hi @Anonymous 

 

You can modify the formula to the following:

 

Previous Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), YEAR([Date]) = YEAR(TODAY()) - 1))
RETURN
CALCULATE(MAX([Score]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), [Date] = _maxDate))

 

Current Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), YEAR([Date]) = YEAR(TODAY())))
RETURN
CALCULATE(MAX([Score]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID], 'Table'[Category]), [Date] = _maxDate))

 

Output:

vxuxinyimsft_0-1718873128626.png

 

Best Regards,
Yulia Xu

 

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

Anonymous
Not applicable

Hi @Anonymous , can we do the same calculation based on the selected year?

Anonymous
Not applicable

Thank you @Anonymous for the quick help

Anonymous
Not applicable

Hi @Anonymous 

 

You can create two calculated columns.

Current Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID]), YEAR([Date]) = YEAR(TODAY())))
RETURN
CALCULATE(MAX([Score]), FILTER('Table', [Date] = _maxDate))

 

Previous Year Max Score = 
VAR _maxDate = CALCULATE(MAX([Date]), FILTER(ALLEXCEPT('Table', 'Table'[Project ID]), YEAR([Date]) = YEAR(TODAY()) - 1))
RETURN
CALCULATE(MAX([Score]), FILTER('Table', [Date] = _maxDate))

 

Output:

vxuxinyimsft_0-1718760871759.png

 

Best Regards,
Yulia Xu

 

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.