cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ARMHCI
Frequent Visitor

DAX return value based on Max value in a new column

Hi, 

 

I have the following table 

 

NumberGenderGivenNameSurnameFamily IDAssetsFamily_age
1femaleAnnaFriedman300115,00052
2maleLelioAlonzo300110,00051
3maleLovrePavić300115,00034
4femaleSusanneIsaksen300111,00060
5maleØysteinHolst300112,00020
6femaleRosauraTrentino30019,00033
7maleArgimiroLuna500120,00060
8femaleAlbikaGodina500130,00075
9maleZainMitchell500133,00031
10femaleTizianaSagese500110,00022
11femaleDorottyaHajdu500153,00070
12maleJohanLennert50013,00023
13maleDarisSore200110,00063
14maleFalcoBarraza2001100,00050
15maleBenedettoGreco200163,00020
16maleMakotoNumata2001100,00050
17femaleSamiraGrigoryeva200181,00035
18maleAlessioPadovano200123,00085

 

I would like to be able to create a column that contains the FAMILY_AGE corresponding to the Max value in ASSETS for a specific FAMILY_ID. 

for example; for FAMILY_ID 3001 the max ASSETS is 15,000. That 15,000 correspond to 52 in FAMILY_AGE. Return in the new column Age_Max_assets_per_family_ID   52   in all rows that correspond to FAMILY ID 3001.

 

The result would look like something like this :

 

NumberGenderGivenNameSurnameFamily IDAssetsFamily_ageAge_Max_assets_per_family_ID
1femaleAnnaFriedman300115,0005252
2maleLelioAlonzo300110,0005152
3maleLovrePavić300115,0003452
4femaleSusanneIsaksen300111,0006052
5maleØysteinHolst300112,0002052
6femaleRosauraTrentino30019,0003352
7maleArgimiroLuna500120,0006070
8femaleAlbikaGodina500130,0007570
9maleZainMitchell500133,0003170
10femaleTizianaSagese500110,0002270
11femaleDorottyaHajdu500153,0007070
12maleJohanLennert50013,0002370
13maleDarisSore200110,0006350
14maleFalcoBarraza2001100,0005050
15maleBenedettoGreco200163,0002050
16maleMakotoNumata2001100,0005050
17femaleSamiraGrigoryeva200181,0003550
18maleAlessioPadovano200123,0008550

 

Be careful!  for FAMILY_ID 2001 we have 2 similar ASSETS that correspond to 2 similar FAMILY_AGE. (see rows 14 and 16).

 

Thanks in advance for the help 

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

Hi @ARMHCI 
You can try the following

 

Age_Max_assets_per_family_ID =
VAR CurrentIDTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Family ID] ) )
VAR MaxAsset =
    MAXX ( CurrentIDTable, Data[Assets] )
VAR Result =
    MAXX ( FILTER ( CurrentIDTable, Data[Assets] = MaxAsset ), Data[Family_age] )
RETURN
    Result

 

In case of duplicates this code will return the maximum age. We can return the minumum or concatinate the results upon your requirement. Please let me know is this is ok with you.

View solution in original post

5 REPLIES 5
Whitewater100
Solution Sage
Solution Sage

Hello:

Continuing on the great answers already given, and building off of amitchandak reply you can try two columns:

Rank = rankx(filter(ALL(Families), Families[Family ID] = earlier(Families[Family ID])),[Assets])
 
Then:
Max Age/Family-Assets =
var family = Families[Family ID]
var topvalue = rankx(filter(ALL(Families), Families[Family ID] = earlier(Families[Family ID])),[Assets])
return
CALCULATE(MAX(Families[Family_age]),
 
FILTER(ALL(Families),Families[Family ID] = family &&
Families[Rank] = 1))
 
Whitewater100_0-1648041843691.png

 

amitchandak
Super User
Super User

@ARMHCI , create two new columns

 

Rank = rankx(filter(Table, Table[Family ID] = earlier([Family ID])), [Assets])

 

 

Age_Max_assets_per_family_ID =
var _min = minx(filter( Table, Table[Family ID] = earlier([Family ID]) && [Rank] =1), [ID])
return
maxx(filter(Table, Table[ID] = _min && Table[Family ID] = earlier([Family ID])), [Family_age])



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Thank you for the solution

tamerj1
Community Champion
Community Champion

Hi @ARMHCI 
You can try the following

 

Age_Max_assets_per_family_ID =
VAR CurrentIDTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Family ID] ) )
VAR MaxAsset =
    MAXX ( CurrentIDTable, Data[Assets] )
VAR Result =
    MAXX ( FILTER ( CurrentIDTable, Data[Assets] = MaxAsset ), Data[Family_age] )
RETURN
    Result

 

In case of duplicates this code will return the maximum age. We can return the minumum or concatinate the results upon your requirement. Please let me know is this is ok with you.

ARMHCI
Frequent Visitor

Thank you, your solution worked too

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors