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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
plugwater
Frequent Visitor

Choose two columns based on max value

Hi,

Source table

IDCategoryValue
10A10
10B15
20A20
20B20

Target format

IDCategoryValue
10B15
20A20

Get the ID and Category based on value, if the values are same then get any ID and Category.

Please help.

1 ACCEPTED SOLUTION

Hi @plugwater ,

 

Maybe you need to change the DAX format because of different regions.

Measure =
VAR max_value =
    CALCULATE ( MAX ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ) 
VAR ct =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Category], 1 ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Value] = max_value )
    ) 
RETURN
    IF (
        MAX ( 'Table'[Value] ) = max_value
            && MAX ( 'Table'[Category] ) = ct,
        1,
        0
    )

test_Choose two columns based on max value2.PNG

 

test_Choose two columns based on max value3.PNG

 

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

View solution in original post

9 REPLIES 9
amitchandak
Super User
Super User

@plugwater ,

Try like this for category lastnonblankvalue(table[Value],min(Table[Category]))

use value as unsummarized

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks, May i know how to use unsummarized ?

I am really new to power BI so would appreciate more details on the formula. 

Hi @plugwater ,

 

Create a measure and apply it to visual level filter.

Measure = 
var max_value = CALCULATE(MAX('Table'[Value]),ALLEXCEPT('Table','Table'[ID]))//calculate the max value of each id
return IF(MAX('Table'[Value])=max_value,1,0) //Determine whether the current value is equal to the max value

test_Choose two columns based on max value.PNG

Sample .pbix

These websites will help you learn DAX.

https://docs.microsoft.com/en-us/dax/ 

https://www.sqlbi.com/topics/dax/ 

 

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

Thanks, I could get the values you mentioned. But in the last two rows in your screenshot, i need only one entry.

Is it possible ? 

Hi @plugwater ,

 

Sample .pbix has been updated

Measure = 
var max_value = CALCULATE(MAX('Table'[Value]),ALLEXCEPT('Table','Table'[ID]))
//calculate the max value of each id
var ct = CALCULATE(FIRSTNONBLANK('Table'[Category],1),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Value]=max_value))
//any category
return IF(MAX('Table'[Value])=max_value&&MAX('Table'[Category])=ct,1,0) 
//Determine whether the current value is equal to the max value

 

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

Hi Liang,

Thanks.

It seems the formula has some issues - A single value for column cannot be determined

Aggregate by PL is the value/amount.

plugwater_0-1597050456062.png

Hi @plugwater ,

 

Based on the sample data you provided, the pbix I created can get the expected results. You can download the pbix I provided for comparison and find out the issue.

 

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

Please provide access to download the pbix file.

User can't be found in the qiuyunus-my.sharepoint.com directory

Hi @plugwater ,

 

Maybe you need to change the DAX format because of different regions.

Measure =
VAR max_value =
    CALCULATE ( MAX ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ) 
VAR ct =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Category], 1 ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Value] = max_value )
    ) 
RETURN
    IF (
        MAX ( 'Table'[Value] ) = max_value
            && MAX ( 'Table'[Category] ) = ct,
        1,
        0
    )

test_Choose two columns based on max value2.PNG

 

test_Choose two columns based on max value3.PNG

 

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.