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
Anonymous
Not applicable

Conditional LOOKUP in PowerBI

Hello, I have a table with four columns - Store, Code, Avg Dist and Max Avg Dist(Max of Avg Dist for each store)
I am trying to find the Code which has the Max Avg Dist for each store. For example in below table - For Store A, the max avg dist is 2000 which is for code '123' and this code is populated in the right most column.

 

 

StoreCodeAvg DistMax Avg DistCode with High Avg Dist
A12320002000123
A23410202000123
A45616002000123
B12315601900789
B45613401900789
B78919001900789
B9112601900789
1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

You can create a column as below:-

Code with High Avg Dist = 
VAR _high_avg =
    CALCULATE (
        MAX ( 'Table (2)'[Avg Dist] ),
        FILTER ( 'Table (2)', 'Table (2)'[Store] = EARLIER ( 'Table (2)'[Store] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table (2)'[Code] ),
        FILTER (
            'Table (2)',
            'Table (2)'[Avg Dist] = _high_avg
                && 'Table (2)'[Store] = EARLIER ( 'Table (2)'[Store] )
        )
    )

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

1 REPLY 1
Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

You can create a column as below:-

Code with High Avg Dist = 
VAR _high_avg =
    CALCULATE (
        MAX ( 'Table (2)'[Avg Dist] ),
        FILTER ( 'Table (2)', 'Table (2)'[Store] = EARLIER ( 'Table (2)'[Store] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table (2)'[Code] ),
        FILTER (
            'Table (2)',
            'Table (2)'[Avg Dist] = _high_avg
                && 'Table (2)'[Store] = EARLIER ( 'Table (2)'[Store] )
        )
    )

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.