Filter lookup and then get latest value

Are you using our SaaS platform (Baserow.io) or self-hosting Baserow?

Self-hosted

What do you need help with?

I have 2 tables:
v1_klienci - list of clients
v1_sprzedaz - list of sales for each client.

Both are linked.
In v1_klienci there is linked field v1_sprzedaz.

My goal is to create field in v1_klienci to get latest specific sale to show expiration duration for sale.
I was able to do trick with date - because it has fixed length.
Now I want to do the same for duration which is not fixed anymore. Values could be like :-90, 234,1,24.

max(filter(
lookup(‘v1_sprzedaz’, ‘valid_for’)
,
lookup(‘v1_sprzedaz’,‘is_X’) = true
))

I got:

Error with formula: argument number 1 given to function max was of type array but the only usable type for this argument is a list of text, or number, or char, or date, or duration values obtained from a lookup.

In attachment you can find screenshots of values I want to max.

Please attach screenshots or videos if they help illustrate your question.

Screenshot from 2025-07-02 05-46-49.png

Hi @parhelium ,
if I get it right your request might be simular to one I asked before. Please check this post.

Maybe this can be also a solution for you?

Thanks for trying to help.
My case is more complicated.

@frederikdc ?

Hi, I tried to simulatie your use case with a table Clients and Sales

I used the following formula to show the duration of the last sale:
filter(lookup('Sales','Duration'),lookup('Sales','Date') = max(lookup('Sales','Date')))

I filter the sales by the last date using the max() function. But instead of showing the date, I show the Duration field.

That looks like good idea, however my case is little more complicated.

In your case Sales.Date is simple date field.

In my case v1_sprzedaz.wazny_do is formula which returns Date:

if(
isblank(field(‘wazny_do_custom’)),
field(‘sprzedano’) + lookup(‘oferta’, ‘waznosc’),
field(‘wazny_do_custom’)
)

Based on your solution I created formula:

filter(
lookup(‘v1_sprzedaz’, ‘wazny_przez’),
AND(
lookup(‘v1_sprzedaz’,‘is_correct’) = true,
lookup(‘v1_sprzedaz’,‘wazny_do’) = max(lookup(‘v1_sprzedaz’,‘wazny_do’))
)
)

However I received error:

Error with formula: argument number 1 given to function max was of type array but the only usable type for this argument is a list of text, or number, or char, or date, or duration values obtained from a lookup.