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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register 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] ) )
)
)
 

 

    Microsoft MVP
 

 

   


      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.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule 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] ) )
 

 

    Microsoft MVP
 

 

   


      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.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule 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] ) )
)
)
 

 

    Microsoft MVP
 

 

   


      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.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.