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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
SivaSatya
Regular Visitor

How to obtain the max value for several rows with the same id with condition

Hello, I need to calculate in a new colum/new measure the max date for the same id within a table and also check if it is less than today. if yes, that value/date to be taken else check the next max date and check if is less than today and so on.... 

 

SivaSatya_0-1636638740191.png

SivaSatya_1-1636638753742.png

 

1 ACCEPTED SOLUTION

Picture1.png

Weight Measure =
VAR currentID =
MAX ( Data[ID] )
VAR newtable_onorbeforetoday =
FILTER ( ALL ( Data ), Data[Date] <= TODAY () && Data[ID] = currentID )
VAR groupbytable =
GROUPBY (
newtable_onorbeforetoday,
Data[ID],
"@maxdate", MAXX ( CURRENTGROUP (), Data[Date] )
)
RETURN
IF (
HASONEVALUE ( Data[ID] ),
CALCULATE (
MAX ( Data[Weight] ),
KEEPFILTERS ( TREATAS ( groupbytable, Data[ID], Data[Date] ) )
)
)
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
SivaSatya
Regular Visitor

Thank You Kim... It is working fine.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Picture1.png

 

New Table =
VAR newtable_onorbeforetoday =
FILTER ( Data, Data[Date] <= TODAY () )
VAR groupbytable =
GROUPBY (
newtable_onorbeforetoday,
Data[ID],
"@maxdate", MAXX ( CURRENTGROUP (), Data[Date] )
)
RETURN
CALCULATETABLE ( Data, TREATAS ( groupbytable, Data[ID], Data[Date] ) )
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank You Kim... New Table is working fine.. Is it possible through new coumn/measure to get this in report? 

Picture1.png

Weight Measure =
VAR currentID =
MAX ( Data[ID] )
VAR newtable_onorbeforetoday =
FILTER ( ALL ( Data ), Data[Date] <= TODAY () && Data[ID] = currentID )
VAR groupbytable =
GROUPBY (
newtable_onorbeforetoday,
Data[ID],
"@maxdate", MAXX ( CURRENTGROUP (), Data[Date] )
)
RETURN
IF (
HASONEVALUE ( Data[ID] ),
CALCULATE (
MAX ( Data[Weight] ),
KEEPFILTERS ( TREATAS ( groupbytable, Data[ID], Data[Date] ) )
)
)
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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