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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Return a different value based on MAX value

Hi all, 
 
I wonder if someone can lend a hand with pointing me in the direction of how to get a value which is associated with the maximum contract number.
 
My Calculated table to get and return the latest contract number is: 
LastContract =
VAR ContractNo = 'Table'[ContractCheck]
RETURN
MAXX(FILTER( ALL( 'Table' ) , 'Table'[ContractCheck] = ContractNo ), 'Table'[Contract no] )
 
Which seems to work at getting me the latest contract issue number, but associated to this is a date (which may or may not be earlier/later/the same); what I would like to do is have DAX return the associated date as part of another calculated column. I only want one value (the latest date on the contract) to be returned for each LastContract no. 
 
If it was just a case of looking at the MAX value again I can see how that would work, but because the date might be an earlier date I need for the formula to look at the LastContract and return the associated date.
 
Thanks
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

If you use column ,you could try it.

Column = IF([Date]=  CALCULATE(MIN([Date]),FILTER('Table',[Head Contract No]=EARLIER([Head Contract No]))),[Date],BLANK())

Or 

Column=CALCULATE(MIN([Date]),FILTER('Table',[Head Contract No]=EARLIER([Head Contract No])))

vyalanwumsft_0-1649753286390.png

IF you want to create a calculate table.

New table = SUMMARIZE('Table',[Name],[Head Contract No],"Date1",CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),[Head Contract No]=EARLIER([Head Contract No]))))

The final output is shown below:

vyalanwumsft_1-1649753503805.png


Best Regards,
Community Support Team _ Yalan Wu
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

7 REPLIES 7
Anonymous
Not applicable

Can you try below as column or Measure

CALCULATE(
MIN('Table'[Date]),
ALLEXCEPT('Table','Table'[Name],'Table'[Head Contract No])
)
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

If you use column ,you could try it.

Column = IF([Date]=  CALCULATE(MIN([Date]),FILTER('Table',[Head Contract No]=EARLIER([Head Contract No]))),[Date],BLANK())

Or 

Column=CALCULATE(MIN([Date]),FILTER('Table',[Head Contract No]=EARLIER([Head Contract No])))

vyalanwumsft_0-1649753286390.png

IF you want to create a calculate table.

New table = SUMMARIZE('Table',[Name],[Head Contract No],"Date1",CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),[Head Contract No]=EARLIER([Head Contract No]))))

The final output is shown below:

vyalanwumsft_1-1649753503805.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Excellent - thank you!

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a measure.

Measure = CALCULATE(MIN('Table'[Date]),FILTER(ALLSELECTED('Table'),[Head Contract No]=MAX([Head Contract No])))

The final output is shown below:

vyalanwumsft_0-1649732209277.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-yalanwu-msft 

Excellent - that works! 

 

If I wanted to use this in a calculated column (so I could then apply it in other calculations for example) is there an easy way to do this? Or would it require a different approach? 

amitchandak
Super User
Super User

@Anonymous
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak Sorry for the delay - example data below:

NameHead Contract NoContract NoDate
Mr. Smith100080001/02/2022
Mr. Smith100080501/01/2022
Mr. Smith101081001/05/2022
Another person105105001/05/2023

 

In this example, I would like the results returned to be:

Mr Smith, 100, 01/01/2022

Mr Smith, 101, 01/05/2022

Another person, 105, 01/05/2023

 

So my code can figure out the contract no, and then return the highest head contract associated with it - but I need to figure out how to get the date from the most recent contract returned.

 

It may be something that I could approach from another angle, if so, any advice is welcome. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors