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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
sslezic
Helper I
Helper I

For all kinds in one column pick value in second column based on aggregation in third

I apologize if this is an obvious solution and has been covered many times before. There is just so much noise when searching for a simple solution.

 

The following is a representative table for the data I have:

sslezic_0-1706042157073.png

 

I'd like: for each Type get Name that has max Value.

 

So in this case my result would be a table with two rows that have Name values Y and X in them. I don't care how much of the original rows I keep (I can always extract Names out of there).

2 ACCEPTED SOLUTIONS

@Anonymous thank you for your reply. It does work as advertised as long as it's displayed along with the other values. Your solution did eventually help me along to my final implementation.

 

For posterity:

 

I ended up adding a new calculated column in my original table (or at least imported from the source):

GreatestValue = 
MAXX(
    FILTER(
        'Table',
        'Table'[Type] = EARLIER('Table'[Type])),
    'Table'[Value]
)

 

Then I generated a new table in my data set:

Table2 = 
SELECTCOLUMNS(
	CALCULATETABLE(
		Table,
		Table[Value] = Table[GreatestValue]
	),
	"Type", Table[Type],
	"Name", Table[Name],
	"Value", Table[Value]
)

 

I'm sure this can be done more elegantly (and if someone is up for the challenge, please feel free), but it does allow me to manipulate the data as needed in my visualizations.

View solution in original post

It seems I was premature in my celebration. As much as my previous solution worked in Desktop Power BI, I could not upload it to the service as the data behind my calculation table is a DirectQuery source from another Power BI dataset.

 

Final solution that did work was a new column on my DirectQuery table that does the following:

 

LargestValue = 
VAR Result =
MAXX(
    FILTER(
        'Table',
        'Table'[Type] = EARLIER('Table'[Type])),
    'Table'[Value]
)
RETURN
IF(
    'Table'[Value] = Result,
    'Table'[Value],
    BLANK()
)

 

Then in my visual I just filter out blanks and everything works as I need it to.

 

I also realize that this is close to the original solution proposed, but with a few differences. Once, it's not a measure, but a new column. Two, it has less MAX's throughout.

 

Thank you @Anonymous for the inspiration though.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @sslezic ,

Please follow these steps:

1.Create a measure to get the name of the maximum value corresponding to each type.

max_name =

VAR _max_value = MAXX(FILTER(ALL('Table'),'Table'[Type] = MAX('Table'[Type])),'Table'[Value])

RETURN

IF(MAX('Table'[Value]) = _max_value,

MAX('Table'[Name]),

BLANK())

2.The result obtained is shown below.

vkaiyuemsft_0-1706060516927.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous thank you for your reply. It does work as advertised as long as it's displayed along with the other values. Your solution did eventually help me along to my final implementation.

 

For posterity:

 

I ended up adding a new calculated column in my original table (or at least imported from the source):

GreatestValue = 
MAXX(
    FILTER(
        'Table',
        'Table'[Type] = EARLIER('Table'[Type])),
    'Table'[Value]
)

 

Then I generated a new table in my data set:

Table2 = 
SELECTCOLUMNS(
	CALCULATETABLE(
		Table,
		Table[Value] = Table[GreatestValue]
	),
	"Type", Table[Type],
	"Name", Table[Name],
	"Value", Table[Value]
)

 

I'm sure this can be done more elegantly (and if someone is up for the challenge, please feel free), but it does allow me to manipulate the data as needed in my visualizations.

It seems I was premature in my celebration. As much as my previous solution worked in Desktop Power BI, I could not upload it to the service as the data behind my calculation table is a DirectQuery source from another Power BI dataset.

 

Final solution that did work was a new column on my DirectQuery table that does the following:

 

LargestValue = 
VAR Result =
MAXX(
    FILTER(
        'Table',
        'Table'[Type] = EARLIER('Table'[Type])),
    'Table'[Value]
)
RETURN
IF(
    'Table'[Value] = Result,
    'Table'[Value],
    BLANK()
)

 

Then in my visual I just filter out blanks and everything works as I need it to.

 

I also realize that this is close to the original solution proposed, but with a few differences. Once, it's not a measure, but a new column. Two, it has less MAX's throughout.

 

Thank you @Anonymous for the inspiration though.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.