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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Using LookupValue to return the Max Value

This is what my data looks like:

AccountIDQuarterMapped Account Name
ABC IncID14320Q3 
ABC Inc.ID14320Q4 
ABC IncorpID14321Q1 
ABCID14321Q2 

 

My goal for the Mapped Account Name column is to return the account name associated with the latest quarter based on the ID.  As you can see these are all the same account, but the naming convention over the quarters has changed.  In this particular case, I want to return "ABC" because that is the name used in the most recent quarter, but my Lookupvalue isn't working correctly yet.

 

This is what I have:

Mapped Account Name =
var erm = Account_Data_Total[ERM ID]
var maxqtr = CALCULATE(MAXX(Account_Data_Total,Account_Data_Total[Quarter]),FILTER(Account_Data_Total,Account_Data_Total[ERM ID]=erm))
return
LOOKUPVALUE(Account_Data_Total[Account],Account_Data_Total[ERM ID],erm,Account_Data_Total[Quarter],maxqtr)
 
It says a table of multitple values was supplied and errors out.
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

This works as a calculated column. If you want to use it as a measure, then you need an aggregating function for Account_Data_Total[ERM ID] in your definition of VAR erm.

 

Try this:

Mapped Account Name =
VAR erm = SELECTEDVALUE ( Account_Data_Total[ERM ID] )
VAR maxqtr =
    CALCULATE (
        MAXX ( Account_Data_Total, Account_Data_Total[Quarter] ),
        FILTER ( Account_Data_Total, Account_Data_Total[ERM ID] = erm )
    )
RETURN
    LOOKUPVALUE (
        Account_Data_Total[Account],
        Account_Data_Total[ERM ID], erm,
        Account_Data_Total[Quarter], maxqtr
    )

 

View solution in original post

3 REPLIES 3
speedramps
Super User
Super User

Hi iab_pbi
 
Try this measure
it gets the last quarter for the ID
and then get the account for the last quarter for the id
 

Remember we are BI community voluntrees so please click the thumbs-up for me taking the trouble to help you and then accept the solution if it works.  Thank you !
 
 
Map =
VAR lastquarter =
CALCULATE(
MAX(Facts[Quarter]),
ALLEXCEPT(Facts,Facts[ID])
)

RETURN
CALCULATE(
SELECTEDVALUE(Facts(Account]),
ALLEXCEPT(Facts,Facts[ID]),
Facts[Quarter] = lastquarter
)
VahidDM
Super User
Super User

HI @Anonymous 

Try this code to add a new column to your table:

Mapped Account Name =
CALCULATE (
    MAX ( [Account] ),
    FILTER (
        'Table',
        'Table'[ID] = EARLIER ( 'Table'[ID] )
            && 'Table'[Quarter]
                = CALCULATE ( MAX ( 'Table'[Quarter] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
    )
)

 

Output:

VahidDM_1-1635371804827.png

 

 

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

Appreciate your Kudos!!

 

AlexisOlson
Super User
Super User

This works as a calculated column. If you want to use it as a measure, then you need an aggregating function for Account_Data_Total[ERM ID] in your definition of VAR erm.

 

Try this:

Mapped Account Name =
VAR erm = SELECTEDVALUE ( Account_Data_Total[ERM ID] )
VAR maxqtr =
    CALCULATE (
        MAXX ( Account_Data_Total, Account_Data_Total[Quarter] ),
        FILTER ( Account_Data_Total, Account_Data_Total[ERM ID] = erm )
    )
RETURN
    LOOKUPVALUE (
        Account_Data_Total[Account],
        Account_Data_Total[ERM ID], erm,
        Account_Data_Total[Quarter], maxqtr
    )

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.