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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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