...
Here is the calculate expression:
coalesce(instance('ledgerledgerdb')/ledgerdb/ledger[@entity-id=case_id]/section[@section-id='balance']/entry[@id=current()/../@id], 0)
...
Looking at the ledger reference
instance('ledgerledgerdb')/ledgerdb/ledger[@entity-id=case_id]/section[@section-id='balance']/entry[@id=current()/../@id]
case_id: put here the id of the case where you want to get your ledger from. For example instance('commcaresession')/session/data/case_id = the current case ID.
So instance('ledgerledgerdb')/ledgerdb/ledger[@entity-id=instance('commcaresession')/session/data/case_id]
Says grab the ledger for this case
/section[@section-id='balance']
Says grab the section called “balance” (this corresponds to the “balance ID”). You could use here 'stock', 'consumption' ...
/entry[@id=current()/../@id]
Says grab the entry value with the ID of the current product
...