Forum

Notifications
Clear all

LAMBDA

7 Posts
2 Users
0 Reactions
112 Views
 KM
(@kasey)
Posts: 24
Eminent Member
Topic starter
 

How would I write this formula as LAMBDA ...

=IF(NOT(ISBLANK([@[Sell ID]])),
IF(EXACT([@Ccy],"GBp"),ROUND([@Quantity]*XLOOKUP([@[Sell ID]],[BUY ID],[Share Price]),6)/100,
ROUND([@Quantity]*XLOOKUP([@[Sell ID]],[BUY ID],[Share Price]),6))
-[@[Cost Value]],"")

 

Many thanks

PS I thought I posted this earlier but I couldn't find it so reposted it. Apologies if it is indeed already on the forum

 
Posted : 04/06/2025 6:24 am
Riny van Eekelen
(@riny)
Posts: 1233
Member Moderator
 

@kasey

What purpose would a LAMBDA serve in this case? You have some repetition of functions in it that you could avoid with LET, and thus shorten the formula. Please upload a file with some example data. Then we don't have to recreate from scratch.

 
Posted : 04/06/2025 2:30 pm
 KM
(@kasey)
Posts: 24
Eminent Member
Topic starter
 

I have attached a mock up. I would be grateful for any advice! 

Thank you for you time 

 
Posted : 04/06/2025 8:22 pm
Riny van Eekelen
(@riny)
Posts: 1233
Member Moderator
 

@kasey 

Thanks! I understand you have some stock listed in "GBPounds" and some in "GBpence".

In the Transactions table you could use LET to make it a bit easier to read and it should pick-up the difference between GBp and what is not GBp.

But your original formula should also work. So, I don't understand your issue with the "orange" cells.

=LET(
div, IF(EXACT([@Ccy], "GBp"), 100, 1),
calc,ROUND([@Quantity]*XLOOKUP([@[Sell ID]],[BUY ID],[Share Price]),6),
IFERROR(calc / div - [@[Cost Value]], "")
)

 

 
Posted : 04/06/2025 9:28 pm
 KM
(@kasey)
Posts: 24
Eminent Member
Topic starter
 

I want to calculate the Profit & Loss on the ORANGE rows but I get the circular error, therefore, can't do calculations on these

 
Posted : 04/06/2025 10:09 pm
Riny van Eekelen
(@riny)
Posts: 1233
Member Moderator
 

@kasey 

OK, so you want the total realised (sell) and unrealised (no sell) results. Then I suggest you insert a column that calculates the quantity 'on hand' for rows with no Sell-ID. That makes it a lot easier. Then use the following LET formula (file attached):

=LET(
div, IF(EXACT([@Ccy], "GBp"), 100, 1),
sell, NOT(ISBLANK([@[Sell ID]])),
calcsold,ROUND([@Quantity]*XLOOKUP([@[Sell ID]],[BUY ID],[Share Price]),6)/ div - [@[Cost Value]],
calcunsold, ROUND([@QtyOnHand]*([@[Today''s Price]]-[@[Share Price]]),6)/ div,
result, IF(sell, calcsold, calcunsold),
result
)

div sets the divisor based on GBp or anything else

sell, sets TRUE for rows with a Sell-ID, FALSE for those without

calsold, calculates the net result as if the item was sold

calunsold, calculates the net result as if the item was NOT sold

result, if sell = TRUE then return calsold else calunsold

 

 
Posted : 04/06/2025 11:07 pm
 KM
(@kasey)
Posts: 24
Eminent Member
Topic starter
 

@riny thank you so much! 

Learning to use LET just to get to know it, so thank you

 
Posted : 05/06/2025 4:11 am
Share: