report for calculating min inventory value

i should make report for calculating min lowest inventory value. I need help for how c/al code should look like because i’m new in this. And it’s a little bit difficault for me. Report designer is same like a standard report Inventory Value. There are needed:

Last Direct Cost (from the last Purchase-Invoice without a project reference) (=Item ledger entry with Document Type=Purchase Invoice and Value Entry =Purchase Invoice)

Lowest Inventory Value (Minimum of the combination of (Invoiced Quantity * Last Direct Cost out of the latest invoice and the Cost Amount (Actual)

Devaluation Value (=Cost Amount (Actual)-Lowest Inventory Value)

I think that first should be filtered Item Ledger Entry ( with Item No, Entry Type,Job No=’’), and after that should be filtered Value Entry (with Item Ledger Entry No,Document Type , Posting date, Value Type), but how all that will be written with c/al (first SETRANGE on Item Ledger Entry, after that on Value entry…FIND(-)…Calculations…???)

I will be very grateful if you answer, this is very important report for me