Help with formula (MIN) with conditions

Hi, for my document where I list my investments in stocks and check possible new investments I have listed my actual and past investments in the widget A (“Aangekocht en/of verkochte aandelen”).
In the widget BC (“Transacties”) all transactions have been listed.

So in the field “Huidig” (= current) of widget A the actual rate of the stocks are listed. In field “Tarief” the rate is listed what I actually bought or sold the stocks for. In the field B I have listed the received dividend.

My problem is that in the field “Aankoop” (bought) I have the formula MIN(Transacties.lookupRecords(Bedrijf=$id).Tarief). I want this changed because this should only be used for fields in which “Aantal” > 0. MIN(Transacties.lookupRecords(Bedrijf=$id, Aantal >0).Tarief) gives an error, who can help me?

lookupRecords doesn’t support conditions (like Column<23). You first need to add a formula Column, with that condition precalculated (like new column "IsGreaterThen23), to the target table, and then use that column in the lookup method.

Thanks it worked,

I added a field named “Aankoop” (if $Soort == “Aandelen” and $Aantal > 0:return True else: return False)
And changed the formula in MIN(Transacties.lookupRecords(Bedrijf=$id,Aankoop=True).Tarief)

Now my page is as follow:

In another database where the bookkeeping is shown I managed to calculate the sum of all transactions where year = 2014 and ledger = ledger from mutations.

First I needed to add a widget for mutations grouped by the 2 fields (year and ledger). That widget I have hidden. In the ledger page I added a field where I calculated all mutaties for 2023 with the following formula:

lookup_records = Mutations_summary_Year_accountID.lookupRecords(accountID=rec)

Filter the lookup records based on Year

filtered_records = [record for record in lookup_records if record.Year == 2023]

Extract the Amount values from the filtered records

amount_values = [record.Amount for record in filtered_records]

SUM(amount_values)