Hi,
I am working on this since few days and many hours without to find how could I do that by myself, even if I am quite sure that it is not so hard to do :-/
The context :
I receive on a daily basis my portfolio from an outside party : A csv file with let's say 5 columns : Date/ Stock name / Price / Quantity / Type
I have created a macro to import these files in ACCESS, all these files in the same table (maybe here is the source of my problem). So my table looks like this :
Date / Stock Name / Price / Quantity / Type
01 Jan / ABC / 1.05 / 200 /Share
01 Jan / XYZ / 2 / 100 / Bond
02 Jan / ABC / 1.06 / 180 / Share
02 Jan / XYZ / 2.1 / 100 / Bond
03 Jan / ABC / 1.04 / 180 / Share
03 Jan / XYZ / 2.15 / 110 / Bond
The query :
I have created a query to analyse these data with :
- 1st column : Stock Name
- 2nd column : Entry Date
- 3rd column : Exit Date
- 4th column : Currency
- 5th column : Entry Price
- 6th column : Exit Price
- 7th column : Performance (= Exit Price / Entry Price - 1)
So, my SQL query is :
SELECT Last(Portfolio.Stock_Name) AS Sec_Name,
Min(Portfolio.[Date]) AS Entry_Date,
Max(Portfolio.[Date]) AS Exit_Date,
Portfolio.Ccy,
First(Portfolio.Price) AS Entry_Price,
Last(Portfolio.Price) AS Exit_Price,
IIf([Entry_Price]=0,0,IIf([Exit_Price]=0,0,[Exit_Price]/[Entry_Price]-1)) AS Perf,
Max([Quantity]) as Quantity_May
FROM Portfolio
WHERE (Portfolio.Type)="Shares")
GROUP BY Portfolio.Ccy, Portfolio.Stock_Name
ORDER BY Last(Portfolio.Stock_Name);
So everything is fine except for the Entry_Price and the Exit_Price. Indeed, the "First" and "Last" function of ACCESS is quite a mess and returns value depending of their creation date in the database.
Thus, I do not know how to do to find a price depending a "Stock Name" and a "Date".
I have tried to work with WHERE, to work with a sub-query, to replicate the table and work with INNER JOIN and Table_2 as portfolio but without figures out it.
As I said, I am quite sure that this kind of work is a basic stuff and a "Must to know how" but everyone had been a beginer with ACCESS :-/
I would appreciate your assistance
I am working on this since few days and many hours without to find how could I do that by myself, even if I am quite sure that it is not so hard to do :-/
The context :
I receive on a daily basis my portfolio from an outside party : A csv file with let's say 5 columns : Date/ Stock name / Price / Quantity / Type
I have created a macro to import these files in ACCESS, all these files in the same table (maybe here is the source of my problem). So my table looks like this :
Date / Stock Name / Price / Quantity / Type
01 Jan / ABC / 1.05 / 200 /Share
01 Jan / XYZ / 2 / 100 / Bond
02 Jan / ABC / 1.06 / 180 / Share
02 Jan / XYZ / 2.1 / 100 / Bond
03 Jan / ABC / 1.04 / 180 / Share
03 Jan / XYZ / 2.15 / 110 / Bond
The query :
I have created a query to analyse these data with :
- 1st column : Stock Name
- 2nd column : Entry Date
- 3rd column : Exit Date
- 4th column : Currency
- 5th column : Entry Price
- 6th column : Exit Price
- 7th column : Performance (= Exit Price / Entry Price - 1)
So, my SQL query is :
SELECT Last(Portfolio.Stock_Name) AS Sec_Name,
Min(Portfolio.[Date]) AS Entry_Date,
Max(Portfolio.[Date]) AS Exit_Date,
Portfolio.Ccy,
First(Portfolio.Price) AS Entry_Price,
Last(Portfolio.Price) AS Exit_Price,
IIf([Entry_Price]=0,0,IIf([Exit_Price]=0,0,[Exit_Price]/[Entry_Price]-1)) AS Perf,
Max([Quantity]) as Quantity_May
FROM Portfolio
WHERE (Portfolio.Type)="Shares")
GROUP BY Portfolio.Ccy, Portfolio.Stock_Name
ORDER BY Last(Portfolio.Stock_Name);
So everything is fine except for the Entry_Price and the Exit_Price. Indeed, the "First" and "Last" function of ACCESS is quite a mess and returns value depending of their creation date in the database.
Thus, I do not know how to do to find a price depending a "Stock Name" and a "Date".
I have tried to work with WHERE, to work with a sub-query, to replicate the table and work with INNER JOIN and Table_2 as portfolio but without figures out it.
As I said, I am quite sure that this kind of work is a basic stuff and a "Must to know how" but everyone had been a beginer with ACCESS :-/
I would appreciate your assistance
Last edited: