"If" condition in an expression?

d0h

Registered User.
Local time
Tomorrow, 07:05
Joined
Mar 23, 2009
Messages
10
pardon my ignorance, i'm very new to access..

i'm doing a college project right now.. and i have a report which shows the stocks purchased/sold by a client..

i'm supposed to calculate the revenue earned from commissions on PURCHASES of stocks by the client.. but my transactions are all in one table. there is an a column (Transaction Type) which could be Buy/Sell entries..
i.e. what i need is to sum up all the Volume * Price * 1% commission, if the transaction type is Buy.

in my report footer.. here's what i have right now

=Sum([Volume]*[Price]*0.01)

how do i set an If statement into the expression builder such that it only takes Buy transactions into account?
 
Look into Iif()...

=Iif([Transaction]="Buy",[Volume]*[Price]*0.01, [Volume]*[Price])
 
thanks for your quick reply!

your method works, but now another error seems to popup..

To count my revenue subtotal from each stock i used:
=Sum(IIf([Type of Transaction]="Buy",[Volume]*[Price]*0.01))

i have this Total Revenue earned field at the page footer, which made use of a hidden runningsum of all the subtotals to count the grand total
but when i used this method of counting subtotal revenue, the runningsum just acts totally weird and counts a wrong number..

any idea why!?
fyi, for the runningsum field, i used the same expression
=Sum(IIf([Type of Transaction]="Buy",[Volume]*[Price]*0.01)), and applied the RunningSum "Over All" the report


or is there another method to count the grand total?
 
oh nevermind i solved it somehow o_o
 
oh..ok here goes

initally for the hidden RunningSum field, i used a =sum() function which contained the exact parameters as the subtotal revenue field

after using the Iif function, it appears that the runningsum wouldnt work properly, so i just replaced it with =[SubtotalRevenue] which is the field containing the subtotal revenue for generated.. and it automatically summed them up without the =sum() function

i not exactly sure why either.. but it works o_o
maybe i made an error in the earlier RunningSum without the Iif function and didn't realise it :s
 

Users who are viewing this thread

Back
Top Bottom