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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Take the column with maximum value based on another value

I have a table like this:

firstans1secondans2thirdans3max
150yes170 yes190no170
190yes    190
110no    0
130no110yes  110
130yes190no170yes170

It's actually a Gabor-Granger analysis survey, stored like this, queue of columns, price, yes/no, second price, yes/no etc. I need to get max column, strugling couple days already, maybe someone could help? Max column take maximum price with according column ans with yes. The price range is 110-130-150-170-190

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , A solution in Power Query, New custom column

 

 

 

let 
_a = Table.Max(Table.SelectRows( Table.FromColumns({
   {[first],[second],[third]},
   {[ans1],[ans2],[ans3]}
}, {"Col1", "Col2"}), each [Col2] = "yes"), "Col1"),
_b= try Record.Field(_a, "Col1") otherwise 0
in 
_b

 

 

 

Dax New Column

 

Column = Maxx(filter(union(row("Col1",[first],"Col2", [ans1]), row("Col1",[second],"Col2", [ans2]),row("Col1",[third],"Col2", [ans3])),[Col2]= "yes"),[Col1])+0
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

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

Here's another Power Query answer:

AlexisOlson_0-1665872457477.png

 

 

List.Max(
    List.Transform(
        {
            { [first],  [ans1] },
            { [second], [ans2] },
            { [third],  [ans3] }
        },
        each if List.Last(_) = "yes"
             then List.First(_) else null // or 0 if you prefer
    )
)

 

 

You can do nearly the same thing in DAX:

 

MAXX (
    {
        ( [first],  [ans1] ),
        ( [second], [ans2] ),
        ( [third],  [ans3] )
    },
    IF ( [Value2] = "yes", [Value1], 0 )
)

 

amitchandak
Super User
Super User

@Anonymous , A solution in Power Query, New custom column

 

 

 

let 
_a = Table.Max(Table.SelectRows( Table.FromColumns({
   {[first],[second],[third]},
   {[ans1],[ans2],[ans3]}
}, {"Col1", "Col2"}), each [Col2] = "yes"), "Col1"),
_b= try Record.Field(_a, "Col1") otherwise 0
in 
_b

 

 

 

Dax New Column

 

Column = Maxx(filter(union(row("Col1",[first],"Col2", [ans1]), row("Col1",[second],"Col2", [ans2]),row("Col1",[third],"Col2", [ans3])),[Col2]= "yes"),[Col1])+0
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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.