Current price by cumulative progress against discrete values - excel

I have to implement a set of formulas in Excel whose requirements seem to defy any logical or succinct way to do them with just formulas.
Short Description:
determine (and display) a timeline of a product's "effective" internal cost each day based on 1) the price paid for the product as a series of bulk purchases, and 2) the company's per-day consumption of the product using the price paid for each purchase, until the purchased amount is consumed and then moving on to the next purchase.
Simplified Details:
We have a sheet "PurchSums" with the product's bulk purchase history: (this is actually a pivot table)
| A | B | C | D |
1: Product Name Purch Date Rate Amount
...
23: Prod-Q 12/18/2012 $3.15 123.7
24: 1/24/2013 $3.05 748.2
25: 2/27/2013 $2.86 650.0
... ...
So initially, the internal price should be $3.15/pound until the first 123.7 pounds are used us, then it should switch to $3.05 and so on.
We have a sheet "Volumes" with consumption by day: (product consumption starts on March 1st)
| A | B | C | D |
1: Product Name 3/1/2013 3/2/2013 3/3/2013 ...
...
12: Prod-Q 87.2 77.1 101.5 ...
... ...
And I need to fill in formulas for the daily price sheet "Prices", which has the product's effective internal price for each day (filled-in by hand now):
| A | B | C | D |
1: Product Name 3/1/2013 3/2/2013 3/3/2013 ...
...
32: Prod-Q 3.15 3.15 3.05 ...
... ...
Note here that the price for "Prod-Q" changed to 3.05 on March 3rd. This is because its cumulative consumption reached 265.8 pounds (87.2 + 77.1 + 101.5) which exceeded the 12/18 purchase of 123.7 pounds and so switched from its price of 3.15 to the price of the next purchase from 1/24.
More Details:
The first sheet "PurchSums" is actually a pivot table, if that helps. Unfortunately, I don't think that it does, nor that GETPIVOTDATA(..) is going to be useful here (but I would be happy to be wrong). The information in it comes from another sheet "Purchases" which is just a list of all of the purchases:
| A | B | C | D |
1: Product Name Purch Date Rate Amount
...
11: Prod-Q 12/18/2012 $3.15 123.7
...
34: Prod-Q 1/24/2013 $3.05 748.2
...
67: Prod-Q 2/27/2013 $2.86 650.0
...
Additional:
First, I would like to do this as much as possible with Formulas in the existing cells/sheets. Plus I would like to minimize the number of additional sheets that have to be added to support this, as the workbook is already pretty substantial.
Secondly, yes I know that I could do this with VBA functions, and I will do that if there's no better way, but I would like to avoid that if possible because in my experience, populating the formulas of large sheets with massive VBA function calls can lead to some significant performance issues.
I would be grateful for any ideas on how to effectively approach this.

So what you are describing is a FIFO inventory accounting system. First In First Out. You might want to read up on it here:
http://en.wikipedia.org/wiki/FIFO_and_LIFO_accounting
and here:
http://accountingexplained.com/financial/inventories/fifo-method
Basically under FIFO you are making the assumption(whether right or wrong) that the first items that you are adding to your inventory are the first ones you are going to use up in your production. As opposed to LIFO which makes the assumption that the last items that you add to your inventory are the first ones that you are going to use up. That would only require a small change in my solution but let's focus on FIFO since that is your question.
So for every day that you operate you need to figure out how much of your inventory you used up and how much you paid for that inventory. So if you bought 20 items at 50 dollars and then another 20 items at 100 dollars the next day - and on the third day you used up 30 of the items in production, you used up (20 * $50 ) plus ( 10 * $100 ) = $2000 worth of inventory. 2000 / 30 = your effective cost of the product for the day(66.6666667). This effective cost is purely informational for the day - you probably wouldn't want to use it for any accounting - although you could with some rounding corrections - it would just be an indirect way to go about it.
So my solution uses a really ugly table. Basically for every day that you operate you need to figure out how much of your inventory you are using up and how much you paid for that inventory - and then divide it by the total amount used up in the day. Something like this should work for you:
=(IF(AND($E8>G$4,$E8>G$5),G$3,0)+IF(AND($E8>G$4,$E8<G$5),($E8-G$4),0))-SUM(G$7:G7)
=(IF(AND($E9>G$4,$E9>G$5),G$3,0)+IF(AND($E9>G$4,$E9<G$5),($E9-G$4),0))-SUM(G$7:G8)
=G8*$C8
=SUM(G13:G15)/G3
These formulas are all auto-fillable. And you could add on to this table as much space as you need(and probably improve it quite a bit). A small program in almost any language could accomplish this much easier and more intuitively than excel - but this works fine.
In practice, oftentimes nobody really knows which pieces of inventory are being used up and thus how much you paid for them. But the system persists nonetheless - usually the reason many accounting practices are done are the same as why the ancient peoples of the earth sacrificed animals - because that's how it's always been done - tradition and folklore. And for the most part it serves them quite well - routine sources of protein are healthy. I could think of some better ways to do it but - alas. Good Luck.

Assuming you know how to:
display product names on every row from the pivot table
extract lower- and upper-bound interval points from the Amount values from the pivot table
sum Volumes from all previous days from the correct row for each product
cover edge cases like volumes outside defined amount intervals
use Office 2007+ tables
use named ranges
...
For the first day, you want the maximum price = the first row for a given product name:
=INDEX(PurchSums[Rate], MATCH(this_row_product_name, PurchSums[Product Name], 0))
For every other day, you want to sum Volumes from all previous days and extract the rate from matching interval of Amounts for a given product name:
=SUMIFS(PurchSums[Rate],
PurchSums[Product Name], this_row_product_name,
PurchSums[Amount above], TEXT(sum_of_previous_volumes_for_product, "<=General"),
PurchSums[Amount up to], TEXT(sum_of_previous_volumes_for_product, ">General"))
Note that sum_of_previous_volumes_for_product > PurchSums[Amount above] and all the other conditions should be met in 1 row only, so we sum exactly 1 row.
Example:
For cell E16 the named ranges would be replaced / point to:
this_row_product_name = Prices[[#This Row],[Product Name]] = Prices[#Product Name] = $B16
sum_of_previous_volumes_for_product = =SUM(OFFSET(Volumes[[#Headers],[2013-03-01]:[2013-03-02]], MATCH(this_row_product_name, Volumes[Product Name], 0), 0)) = SUM($C12:D12)

So basically you want to summarize your "PurchSums" sheet and "Volumes" ones into one that combines the date fields??
If this is the case....
In your summary sheet make a row filled with the dates
Make a column for Purchase amount
Make a column for Volume amount
Under the Purchase amount use a match / index formula like this:
=index({Select the column C from "PurchSums"},match( {Select date from third sheet},{Select date column from "PurchSums"},0))
Similarly do the same thing for the Volume column.
Hope this gets you on your way if I am not far off on what you are trying to accomplish.

Related

How can I determine the 'total cost' from a tiered pricing structure using standard formulas in Excel?

I'm trying to evaluate various tiered pricing structures (for say, electricity plans) using Excel (more-or-less) to see what costing/plan is 'optimal', given some existing usage data I have.
Consider an example 'Table of Usage & Rates' (with fictitious but easily manipulated values):-
For a daily usage value of 120, we'd have 100 (in the 1st tier) and 20 (in the 2nd tier). The amount used within a tier gets charged at a certain rate (the 'factor')... and each 'tier charge' is addded together to form a total charge for the day.
So, we can calculate:-
100 x 8 = 800 ...a part of the total
20 x 4 = 80 ...another part of the total
...and that's all, giving a total of 880.
...but how to do that in a single formula within a cell?
I've done some pretty decent explorations for a few hours today, as I can't nut out how to deal with this... and most suggestions talk about multiple =IF formulas (cumbersome and unscalable - I shouldn't need to recode cell contents if I split/add another tier)... and suggestions with =VLOOKUP just don't 'click' with me ( = I don't understand them).
I'm actually using 'PlanMaker', a component of Softmaker's 'Office 2021' product to create/maintain this spreadsheet.. and there is no VBA-like plugin available.
I'd appreciate a method of attack, if anyone can suggest something, please...
So:
=product(10,8)+product(20,4)
or if we assume Factor starts in B9 then =product(A9,B9)+product(A10,B10+product(A11,B11)
then take the sum of those results etc assuming A9 is the amount used.
You can also use:
=sumproduct(A9:A11,B9:B11)
for the same but only needs one cell. And the advantage of a lot less typing.
You can include a 3rd array in sumproduct (or as many as needed) such as a binary value to include in the calculation or not.

excel PowerPivot Auto Calculated Measures & Columns

After looking at a few similarish questions I figured I needed something more specific so asking here. I will start by explaining the situation:
The Setup
I have a Store which sells Cakes, Cookies and Wine. I have the weekly sales data of each product sorta like this:
Product ID
Product Name
Quantity
Value
Week Ending
1
Ginderbread
2
£4
13/01/22
2
Chocolate chip
5
£25
13/01/22
3
Red Wine Bottle
1
£10
13/01/22
4
Sponge Cake
3
£9
13/01/22
Currently every week's data is stored within the same table, with me using a Week filter to show only the week i'm interested in.
Using this Data I created PivotTables that shows the sales of each category, with the ability to drill down to show the specific products. Table looks something like this:
Category
Quantity
Value
Cakes
2
£4
Cookies
7
£29
Wine
1
£10
The issue
I now want to stick in a new calculated column that shows the Value as a %. E.g The total value for the previous table was £43, so Cookies is about 67%. If I drill down, it would show the Chocolate Chip record as 80% and Gingerbread as 20%
I imagine doing this would be easier if each individual week's data was on a different table, but I got a lot of weeks and I also want to do tables showing the sales for over a period of time. Plus I don't know of a way to merge the "value" and "quantity" columns, etc instead of having 1 for each week being shown.
any advice would be appreciated
Create an extra column in the source table (prior to filtering) entitled "perc" calculated as the corresponding value for each row divdied by the total value across all rows (se pic. / eqn. for first row below) --
=E2/$E$6
No calculated fields required - just include perc as the mesaure of interest in your pivot table, with value setting as 'sum':
The reason why this worked is because of the common denominator - which allows one to sum ratios on a 1:1 basis.
Devising a calculated field using the standard 'fields, items & sets' functionality for ordinary pivot tables would not be feasible / possible as far as I am aware. You would need to move into the realm of power pivots and data models - which is not too complicated (readily accesible directly from the field list per below) - however, I see this as unnecessary complication for the task at hand.
Side notes:
Using table names in your functions is sometimes more convenient when entering, albeit may appear tricky at first when reviewing - first eqn above becomes:
=[#Value]/Table1[[#Totals],[Value]]

Choose correct PRODUCT COST from ROW based on amount sold

I am making a sheet to CALCULATE REAL REVENUE from each sale I make on my online store.
The problem is that the COST of my products is not always constant. It varies depending on many factors so each time I make a purchase I add the NEW PRODUCTS COST (LATEST COST).
Each time I make a new purchase I will add the QUANTITY and the new COST. (PURCHASE 1, PURCHASE 2, PURCHASE 3,etc).
Screenshoot of my sheet with example on ROW 41
In Column B I want to know which is the CURRENT COST based on the amount of TOTAL SALES of each product.
For example:
If I have sold less than 100 ( Pruchase 1 QUANTITY) then I need the formula to choose value of E41 (PURCHASE 1 COST).
If I have sold MORE than 100 and LESS than 300 (which is the SUM of PURCHASE 1 & PURCHASE 2) I need the formula to choose value of G41 (PURCHASE 2 COST) AND SO ON...
The formula I have come up with so far is this:
=INDEX(41:41,,IF(C41<=D41,COLUMN(E41),IF(C41<=D41+F41,COLUMN(E41)+2,IF(C41<=D41+F41+H41,COLUMN(E41)+4,COLUMN(E41)+6))))
This formula WORKS but only for the first 3 PURCHASES.
I need a formula that has no limit but I don't know how to make a VARIABLE formula.
Please take my words literally when I say that I wouldn't waste one minute on trying to solve your problem with your current sheet design. You would need VBA, and then extract quantities and prices from each purchase without the ability to filter on columns. (Minute is up.)
What you need is a Purchase database: ItemID, Date, Quantity, Price, maybe Ref#. From that you can pull out the transactions for any item by filtering on the item and the cost by using functions like SUMIF. However, this just brings the real problem within reach without solving it.
The problem is that when you buy 100 pcs #42 your price is 42. Then you buy another 100 pieces #46 your average price is 44. But if you sold 50 pieces with a cost of 42 then the average cost of the remaining 150 is 45. Therefore you can't determine the average cost of any remainder without knowing the quantity sold and the average cost applied to that sale. To solve that problem you will still need VBA but the suggested db format of purchase record would at least support such a solution.
Not so long ago I programmed a solution where there were additional columns in the db and each sale was recorded in 3 columns (much like your present purchase record): date, Qty, Ref. In this way I could trace the sale of each individual purchase (this was for shares trading). The sale of the newer quantity wouldn't start until the earlier quantity was sold out.
Perhaps you don't need to trace where the purchased quantity went to and just need one column to count down the balance to zero. That would be much simpler but has the drawback that you can't roll back errors. In the end the rollback was the reason why I abandoned the design. The key to the ability to abandon it is a similar db for sales: date, qty, price, Ref#.
With such a setup you might design a system to either extract the average or FiFo price from the purchase side and associate it with a sale. If the condition is that it should be done with worksheet functions you could add a column for "current cost" in the purchase db, changing with each purchase, which you look up by date from the sales side using VLOOKUP or SUMPRODUCT, having set a cost price applicable from the day of purchase until the next. If that appeals to you, a method must be found to deal with days on which there are both purchases and sales.

MS Access Query - display data for each month over multiple years as columns

OK, I am very new at this and have been googling things for the past few hours and have not found anything. Maybe I'm not looking for the right thing or I'm not looking hard enough but I am here now.
I have 3 calculations I need to do for each month (over 5 years) to be displayed as columns (3*12*5=180 total columns). I have mock formulas in Excel:
Fraction of Month =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),IF(FEStart=s01Y15, 1, ((e01Y15-(FEStart))+1)/DAY(e01Y15)),IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),IF(FEEnd=e01Y15, 1, ((FEEnd)-(s01Y15))/DAY(e01Y15)),IF(FEEnd<=e01Y15, 0, IF(FEStart<=s01Y15,1,0))))
Year of Person =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),1,IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),INT((s01Y15-FEStart)/365)+1,IF(FEEnd<= e01Y15, 0, IF(FEStart<=s01Y15,INT((s01Y15-FEStart)/365)+1,0))))
Monthly Salary =([Fraction of Month]*(SF/12))*(1.03^([Year of Person]-1))
Where
FEStart is the Start Date of the Person (entered by user)
s01Y15 is the start of the first month in 2015 (parameter set by me)
FEEnd is the End Date of the Person (entered by user)
e01Y15 is the end of the first month in 2015 (parameter set by me)
SF is the Annual Salary of the person (entered by user)
I understand that IF() has to be changed to IIF() and to use AS to name the field in the query for the sql code. However, I’m trying to see if I can make some sort of loop so I don’t have to manual change the variables and have 180 line written out. If I have to do that, I will. But I would really rather not.
Is there some way to use a while loop or for loop or some other loop to have MS Access create these 180 columns for me, without having 180 lines of code? Or do I just have to copy and paste a ton?
DISCLAIMER: I am using MS Access 2013. Also, I have some experience with VBA code in Excel (and I’m far more comfortable using Excel than MS Access) but am unsure of how to add VBA code to a query (I have added it to my forms).
I also had the idea to change the values of s01Y15 and e01Y15 in each loop but that might be a bit more complicated too so I just have (12*2*5=120) 120 variables set to the start and end dates of every month (which is probably not the best idea in retrospect). Anyways I still cannot get a loop to work in a query (if it even is possible).
EDIT: Not sure if this is helpful, but this is what I have:
Input data for People Table:
Person’s name (separated into f/l), Start/End Date (FEStart/FEEnd), Salary (SF).
People Query to show: Person’s name, Start/End Date (FEStart/FEEnd), Salary (SF), & the 180 columns I described above.
Restrictions on Calculations: Fraction of a Month should be a positive number no larger than 1. Year of person starts as a 1 and increases (by one) after each year (essentially infinitely but I am only doing 5 years – so with a max of 5). Monthly salary can be infinite.
Here is an example for an entry in the People table:
FName | LName | FEStart | FEEnd |SF
Anakin | Skywalker | 7/1/2017 |6/30/2019 |120,000.00
This is a little oversimplified because really the start and end dates are pulled form another table, connected by the “people id”.
Please see the link for the calculations.

Complicated formula required to work out costs including multiple discounts

I'm looking to compute and show individual row totals and a Grand Total. I just need the formulae to put in the boxes so the calculation is automatic but the problem is the calculations are a little complicated...
I'm using data validation to select the day type. This is what I think I need:
Assign a price to the day type (either Standard day = £23 or Extended day = £26).
Apply a volume discount where appropriate. If Jack is attending all week (5 days) and the day type is the same for all (all Standard or all Extended), the total cost is £100 (or £120)
Else the total number of days needs to be added up for Jack. (Number of days for each ‘day type’) and priced up.
For his siblings after the first, as above but apply an additional discount of 15%.
The grand total then needs to show at the bottom.
Well, it is not the best of data layouts but this may serve, in L6 and copied down to L13:
=IF(OR(A6="Brother",A6="Sister"),0.85* IF(COUNTIF(B6:F6,"Standard day")=5,100,IF(COUNTIF(B6:F6,"Extended day")=5,120,COUNTIF(B6:F6,"Standard day")*23+COUNTIF(B6:F6,"Extended day")*26)), IF(COUNTIF(B6:F6,"Standard day")=5,100,IF(COUNTIF(B6:F6,"Extended day")=5,120,COUNTIF(B6:F6,"Standard day")*23+COUNTIF(B6:F6,"Extended day")*26)))
and =SUM(L1:L16) in D16.
It would be better practice not to hard code the daily rates/discount, but extracting these from C1:D2 would have increased the length of the formula further.
Note also the result is not £429.95 (you may have changed your example after doing your calculations).

Resources