This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
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
Solved! Go to Solution.
Hi @rabih,
My mistake. ![]()
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
Hi @rabih,
Could you try using the formula below to see if it works? ![]()
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. ![]()
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 🙂
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 36 | |
| 32 | |
| 26 | |
| 24 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 50 | |
| 31 | |
| 25 | |
| 24 |