Hi all, So for some background. I have a cashflow table that is a one to many relationship, and each ID on TblLoanGeneral has 60 records on tblcashflow.
There are 6 Income columns on TblCashflow. What I need is to pull the last dollar item from the cashflow for each record. I though I could just set the Cashflow date to max, however it pulls the very last record row 60 from tbl cashflow. I need the last AMOUNT that is entered into any one of the six cashflow columns
So for example
I tried using a union to 'stack' all six of the income columns and the max date from tblcashflow for each, and then I would from that be able to take the max cashflow for each record, but I cannot figure out how to do this.
From this example below, I would like just the Payoff Amt since it is the most recent event entered in the cashflow table. Right now I am returning Principal from May, as well as Interest from may and Payoff from August for each record. Just need august
ID
MONTH
PRINCIPAL
INTEREST
FEES
PAYOFF
NOTESALE
REOINCOME
7457 1/1/2014 500 250 7457 2/1/2014 500 250 7457 3/1/2014 500 250 7457 4/1/2014 500 250 7457 5/1/2014 500 250 7457 6/1/2014 7457 7/1/2014 7457 8/1/2014 50,000
Sorry if this is confusing, but basically I am looking for the last item of cashflow as this is our 'reversion' value...the value the final sale value of an asset.
Thanks!
btw my union query looks like this to get them all stacked. (the union is on [reversion]) which gives me the max of each of the columns, but I cant take the max of the max of that for some reason.
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.Principal) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.Principal) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"))
UNION
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.Interest) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.Interest) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"))
UNION
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.Fees) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.Fees) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"))
UNION
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.Payoff) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.Payoff) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"))
UNION
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.NoteSale) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.NoteSale) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"))
UNION
SELECT tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, Last(tblCashFlow.REONOI) AS [Reversion], tblCashFlow.Strategy, Max(tblCashFlow.CFDate) AS MaxOfCFDate, tblLoanGeneral.PortfolioID
FROM tblCashFlow INNER JOIN tblLoanGeneral ON tblCashFlow.LoanID = tblLoanGeneral.ID
WHERE (((tblCashFlow.REONOI) Is Not Null))
GROUP BY tblLoanGeneral.ID, tblLoanGeneral.[MLS Number], tblLoanGeneral.Borrower, tblCashFlow.Strategy, tblLoanGeneral.PortfolioID
HAVING (((tblCashFlow.Strategy)="recommended"));