I have a capex table to calculate investment of a new product.
As shown in pic all numbers are not real numbers
D83 is the initial investment, meaning we invest $15,800 to buy machine and space
E85 to I85 are the variable cost each year.
E86 to I86 are the revenue each year, revenue = price * est.sold quantity
E87=E85+E86, F87=F85+F86, etc.
D91 = {INDEX($E$87:$I$87,MATCH(TRUE,$E$89:$I$89>0,0))} This is an array to find the first positive cash flow of Row 89 and return the value in row 87
D92 = {INDEX($E$83:$I$83,MATCH(TRUE,$E$89:$I$89>0,0))} This is an array to find the first positive cash flow of Row 89 and return the value in row 83
D93 = COUNTIF(E89:I89,"<0")+((-D92)/D91)
In this way, I calculated the payback years of a project.
In cell D98 I need to calculate that given a certain payback year number, other things hold still, what the price needs to be. Since D91 and D92 are arrays to lookup for the first positive cash flow and each year cash flow is not even, I can't think of a formula to put in D98 so D98 changes with C98, for example, if I put 2 in C98 meaning I need the payback period to be 2 years, and D98 will automatically give me a number to show what price it should be.
Is there any formula or VBA to do it?
Related
I'm trying to create a matching algo in pandas that does the following with a given table:
A table contains purchases and sales of products by date, item, quantity (+ for purchases and - for sales) and price.
Conditions:
Create an algorithm that matches purchases and sales per item and the corresponding average profit for each item in total.
Matches can only be on the same date, otherwise they are not matched at all.
Remaining positive or negative inventories per day are ignored
Negative inventories are allowed.
Example with a single product:
date product quantity price
1 X +2 1
1 X -1 2
1 X -2 4
2 X +1 1
2 X +1 2
3 X -1 4
Answer:
The result would be that only on day 1 the 3 trades are matched, with a profit of -2+2+4=4. Because inventory is +2, -1, and then again -1. The remaining inventory of -1 is ignored. Day 2 and 3 have no matches because the trades are not closed on the same day.
Correct output:
product Profit
X +4
Is there any elegant way to get to this result without having to loop over the table multiple times with iterrow?
For reproducing the df:
df = pd.DataFrame({'date':[1,1,1,2,2,3],'product': ['X']*6,'quantity':[2,-1,-2,1,1,-1],'price':[1,2,4,1,2,4]})
The process that you describing could use groupby & aggregate, something like this:
df.groupby('date').sum()
But I don't fully understand your rules for matching. So in Day 1, I got a different total profit. Price * quantity is (+2*1)+(-1*2)+(-2*4)=-8, so profit seems to be 8.
Using iterrow() is a rather bad practice. Not only you're writing excessive code, but also it's likely much slower (check a comparison here).
Most of those type of jobs can be accomplished by combining groupby(), aggregate() and apply(). Check out this great tutorial.
I hope this helps you or future answers :)
For example - Column ABC number(12,4).
My value is 2.7487 and if divided by 2 it's 1.3744 (rounding with 4).
1.3744 + 1.3744 = 2.7488
How do I get a result - 2.7487 as the original.
You cannot. That's normal behavior of finite arithmetic (integer and floating point).
Even if you add large number of decimal places, you'll still lose precision.
This is a typical case of the rounding of an invoice. For example you have an invoice for a total of $100.00 that you need to divide in 3 items. You get three items of $100.00 / 3.0 each one. That is:
$33.33 Item #1.
$33.33 Item #2.
$33.33 Item #3.
For a total of... $99.99! (not the $100.00 that you expected).
The known solution for ages now is to adjust one or more of the values to add or decrease it by one cent. In this case, you could add 1 cent to the last item, to get:
$33.33 Item #1.
$33.33 Item #2.
$33.34 Item #3.
For a total of... $100.00! Perfect.
There are multiple possible combinations (all valid) to adjust those values. That's how it's done in accounting.
I have a data set where you have a Document Property that Selects "items", each "item" has a particular "usage days". I want to calculate an output of "Moving Average" for 1 or more selected items. the data for the moving average lives under a column named "usage days".
How do I calculate this taking into account the "selected date of my choice" and the rolling average number of days of my choice.
Do you have particular ideas of how I can perform the calculation i.e. in a calculated column or a text field?
Car/ Trip / Start Date/ End Date / Days on trip
1 AB123 / 2 / 6/07/2013
1 AB234 / 29/07/2013 / 6/09/2013 / 42
1 AB345 /6/09/2013 /28/09/2013 /22
1 AB456 /29/09/2013 /21/10/2013 /23
2 AB567 / 26/10/2013 / 12/11/2013 / 22
2 AB678 /12/11/2013 /8/12/2013 /26
[The rows above have an example of the problem (sorry couldn't paste an image because im new), I want to calculate the %usage of the Car and or cars for a selected range of time e.g (Select date range JUlY to AUGUST then (#of days on trip for car 1and 2)/#on days in that period)/2*100]
As phiver said, it is still difficult to see what you expect as a result... but I think I have something that might work. First, I slightly altered the dataset you provided, like so:
car trip startDate endDate daysOnTrip
1 AB123 7/6/2013 7/29/2013 23
1 AB234 7/29/2013 9/6/2013 42
1 AB345 9/6/2013 9/28/2013 22
1 AB456 9/29/2013 10/21/2013 23
2 AB567 10/26/2013 11/12/2013 22
2 AB678 11/12/2013 12/8/2013 26
I then added 2 document properties, "DateRangeFirst" and "DateRangeLast", to allow the user to select beginning and ending dates. Next I made input box property controls for each of the aforementioned document properties in a text area so the user can alter the date range. I then added a datatable visualization with a "Limit data using expression:" of "[startDate] >= Date(${DateRangeFirst}) and [endDate]<= Date(${DateRangeLast})" so we could see the trips selected. Finally, to get the average you appear to be looking for, a barchart set to % of total (daysOnTrip) / car with the same data limiting expression as above. The below screenshot should have everything you need to reproduce my results. I hope this gives you what you need.
NOTE: With this method if you select a date in the middle of a trip, an entire row and all of the days on that trip will be ignored.
I have to put together a report every quarter using data pulled off of Morningstar Direct. I have to automate the whole process, or at least parts of it. We have put this report together for the last two quarters, and we use the same format each time. So, we already have the general templates for the report - now I'm just looking for a way to pull the data from Morningstar and putting into the templates correctly.
Does anyone have any general idea where I should start?
A B C D E F
Group Name Weight Gross Net Contribution
Equity 25% 10% 8% .25
IBM 5% 15% 12%
AAPL 7% 23% 18%
Fixed Income 25% 5% 4% .17
10 Yr Bond 10% 7% 5%
Emerging Mrkts
And it goes on breaking things into more groups, and there are many more holdings within each group.
What I want it to do is search until it finds "Equity", for example, and then go over one row, grab the name of the position, its weight, and its net return, and do that for each holding in Equity. The for it to do the same thing in Fixed Income, and on and on - selecting the names, weights, and nets for each holding. Then copy and pasting them into another workbook.
Anyway that is possible?
It sounds like you need to parse your information. By using left(), right(), and mid() you can select the good data and ignore the superfluous. You could separate the data in one cell into multiple cells in the desired format.
A B
Name Address
John Q. Public 123 My Street, City, State, Zip
E (First Name) F (Middle Initial) (extra work to program missing data)
=LEFT(A2,FIND(" ",A2)) =MID(A2,LEN(E2)+1,FIND(" ",MID(A2,LEN(E2)-1,99)))
G (Last Name) H (City)
=MID(A2,(LEN(E2)+LEN(F2)+2),99) =MID(B2,LEN(H2)+2,FIND(",",MID(B2,LEN(H2)+2,99))-1)
I (State)
=MID(B2,(LEN(I2)+LEN(H2)+4),FIND(",",MID(B2,(LEN(I2)+LEN(H2)+4),99))-1)
J (Zip Code)
=MID(B2,(LEN(H2)+LEN(I2)+LEN(J2)+6),99)
This code will parse the name in the cell A2 and address in cell B2 into separate fields.
Similar cuts should allow you to get rid of the unwanted data.
==================================================================
7/8/2015
Your data seems to be your desired output. If so, please provide sanitized input data for comparison. You probably need to loop through your input to find the groups. When the group changes, prepare the summary figures.
I have a cube built on a fact which, amongst others, includes the Balance and Percentage columns. I have a calculation which multiplies the Balance by the Percentage to obtain an Adjusted Value. I now need to have this Adjusted Value divided by the sum of all balances, to get weighted values.
The problem is that this sum of all balances doesn't apply to the whole dataset. Rather, it should be calculated on a filtered subset of the whole data. This filtering is being done in Excel using a pivot table, so i do not know what conditions will be used to filter.
So, for example, this would be the pivot i'd like to see:
ID Balance Percentage Adjusted Value Weighted Adjusted Value
1 100 1.5 115 0.38 (ie 115/300)
2 50 2 51 0.17 (ie 51/300)
3 150 1 150 0.50 (ie 150/300)
300 is obtained by summing the balance of the rows that show in the filtered pivot.
Can this calculation be somehow done in OLAP? Or is it impossible to compute this sum with what i know?
Yes should be possible; e.g., assuming 1/2/3 are the children of a common parent, then the following calculated measure should do the trick :
WAV = AV / ( id.parent, Balance )
If not we would need more information about the actual data model and query.