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
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
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!

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.