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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
rabih
Frequent Visitor

Lookupvalue returns only one value

I have to analyze one table Sales orders based on an older Sales table data. So for each record in the new table I have to find the closest delivered Sales order LastSO (primary key). I grouped the old Sales order in a table based on Customer Date and Maximum RecId for each date. There are no duplicate Deliver date/time and LastSO records. When I created a column ClosestSO as follows:

 

ClosestSO = LOOKUPVALUE(MaxRecIdByDateByCust[LastSO],
     MaxRecIdByDateByCust[Invoice account],NewOrders[Cust2Choose],
    MaxRecIdByDateByCust[Delivery date/time],LASTDATE
    (FILTER
        (ALL(MaxRecIdByDateByCust[Delivery date/time]),
            (MaxRecIdByDateByCust[Delivery date/time])<=NewOrders[DeliveryDate]
        )
    )

 

I only get one record. Any idea why. I used the same logic for Exchange rates and it worked well

OnlyOneRecordFound.pngOnlyOneRecordFoundRelationship.png

1 ACCEPTED SOLUTION

Hi @rabih,

 

My mistake. Smiley LOL

 

Could you try the formula below to see if it works?

ClosestSO =
LOOKUPVALUE (
    MaxRecIdByDateByCust[LastSO],
    MaxRecIdByDateByCust[Invoice account], NewOrders[Cust2Choose],
    MaxRecIdByDateByCust[Delivery date/time], CALCULATE (
        LASTDATE ( MaxRecIdByDateByCust[Delivery date/time] ),
        FILTER (
            ALL ( MaxRecIdByDateByCust ),
            ( MaxRecIdByDateByCust[Delivery date/time] ) <= NewOrders[DeliveryDate]
                && MaxRecIdByDateByCust[Invoice account] = NewOrders[Cust2Choose]
        )
    )
)

 

Regards

View solution in original post

4 REPLIES 4
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @rabih,

 

Could you try using the formula below to see if it works? Smiley Happy

ClosestSO =
LOOKUPVALUE (
    MaxRecIdByDateByCust[LastSO],
    MaxRecIdByDateByCust[Invoice account], NewOrders[Cust2Choose],
    MaxRecIdByDateByCust[Delivery date/time], LASTDATE (
        FILTER (
            ALL ( MaxRecIdByDateByCust ),
            ( MaxRecIdByDateByCust[Delivery date/time] ) <= NewOrders[DeliveryDate]
                && MaxRecIdByDateByCust[Invoice account] = NewOrders[Cust2Choose]
        )
    )
)

 

Regards

I have copied and pasted your code snippet.

Got following error:

Something's wrong with one or more fields:(NewOrders) ClosestSO:

A table expression containing more than one column was specified in the call to function 'LASTDATE'. This is not supported.

 

 

Hi @rabih,

 

My mistake. Smiley LOL

 

Could you try the formula below to see if it works?

ClosestSO =
LOOKUPVALUE (
    MaxRecIdByDateByCust[LastSO],
    MaxRecIdByDateByCust[Invoice account], NewOrders[Cust2Choose],
    MaxRecIdByDateByCust[Delivery date/time], CALCULATE (
        LASTDATE ( MaxRecIdByDateByCust[Delivery date/time] ),
        FILTER (
            ALL ( MaxRecIdByDateByCust ),
            ( MaxRecIdByDateByCust[Delivery date/time] ) <= NewOrders[DeliveryDate]
                && MaxRecIdByDateByCust[Invoice account] = NewOrders[Cust2Choose]
        )
    )
)

 

Regards

You nailed it 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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