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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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

Thank you for the solution

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.

Thank you, your solution worked too

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors