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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Lookup to return only max value

Hi Superheroes!
I am having an issue with my Lookup-function returning a table instead of a single value.

 

I have two relevant tables, plus date.

  1. Account Overview where I keep Customer ID (Number), Product ID (SKU), Year (Year), and price (Price per Unit).
  2. Forecast containing Customer ID (Number), Product ID (SKU), Date (Forecast Shipping Date), and number of units forecasted (Units) which contains plus Units.

 

The Lookup function below is meant to return the price for a product given to a customer for the year in question, and multiply with the number if units.

However, there appears to be duplicates in the Account Overview (excel)table, i.e. multiple prices for the same product for the same customer withing the same year, and I would like to bypass this by having the below formula only return the highest price found. In short, if the formula returns more than one price for the same product to the same customer within the same year, I would only want the highest one.

 

Revenue =
SUMX(f_Forecast, f_Forecast[Units] *
    LOOKUPVALUE('dAccount Overview'[Price per unit],
    
'dAccount Overview'[SKU],      f_Forecast[SKU],
'dAccount Overview'[Number],   f_Forecast[Number],
         'dAccount Overview'[Year],  YEAR(f_Forecast[Forecast Shipping Date])
         )
    )

Any help would be much appreciated!
Daniel

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Revenue =
SUMX (
    f_Forecast,
    f_Forecast[Units]
        * CALCULATE (
            MAX ( 'dAccount Overview'[Price per unit] ),
            FILTER (
                ALL (
                    'dAccount Overview'[SKU],
                    'dAccount Overview'[Number],
                    'dAccount Overview'[Year]
                ),
                'dAccount Overview'[SKU] = f_Forecast[SKU]
                    && 'dAccount Overview'[Number] = f_Forecast[Number]
                    && 'dAccount Overview'[Year] = YEAR ( f_Forecast[Forecast Shipping Date] )
            )
        )
)

 Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous 

Revenue =
SUMX (
    f_Forecast,
    f_Forecast[Units]
        * CALCULATE (
            MAX ( 'dAccount Overview'[Price per unit] ),
            FILTER (
                ALL (
                    'dAccount Overview'[SKU],
                    'dAccount Overview'[Number],
                    'dAccount Overview'[Year]
                ),
                'dAccount Overview'[SKU] = f_Forecast[SKU]
                    && 'dAccount Overview'[Number] = f_Forecast[Number]
                    && 'dAccount Overview'[Year] = YEAR ( f_Forecast[Forecast Shipping Date] )
            )
        )
)

 Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.