Billing Variance Analysis With Many Scenarios - VBA - excel

I was given tens of thousands of bills charged to customers. I am trying to determine if the bills are potentially accurate. The only data I have is the actual bill itself. Here's where things get complicated. There are four scenarios, each with their own nuances:
Scenario 1 Nuances:
Base Fee of $10 * the amount of items bought * the number of deliveries (maximum amount of items bought would be 10 and the maximum number of deliveries would be 7)
If the amount of items bought exceeds 1, the total bill is discounted by 20%
If the boxes are recycled, the total bill is further discounted by 15%
If the good is over 15 pounds, an additional charge of $10 will be assessed per each item over 15 pounds (maximum amount of items would be 10)
If there is no adequate port for delivery, an additional $50 per hour will be charged per delivery (maximum hours would be 3)
Scenario 2 Nuances:
Business that share a port of delivery for the second service will be charged $11 per item
If the business does not share a port of delivery, the fee is $13 per item. Each additionally delivery for a business that does not share a port is $15 per delivery, in addition to each item costing $13 (maximum deliveries would be 7 and maximum amount of items would be 8).
You see where I am going with all of this. The next two scenarios are just as lengthy. Sadly, no information besides the total bill is given. We don't know which scenario the bill belongs to, the number of items, etc., just a single column of the invoice. How would I go about determining all potential costs from each scenario to maybe index the invoice and see if there is a match? Any help on this would be amazing.
I tried creating an index where I wrote out multiple scenarios. For example, a column with the number of items, the number of deliveries, a discount for > 1 item bought, a recycling discount, etc... After attempting this for two hours, I realized this may not be the best method. My first row would be 1 item, 1 delivery, 0% discount for > 1 item bought, and 0% discount for recycling. Next would be 2 items bought, 1 delivery, 20% discount for > 1 item bought, 0% discount for recycling. This is seemingly impossible to do for everything.
My expected output is "Y" if the invoice total matches one of the potential costs from the index, "N" if not.

You can write a macro to calculate every possible scenario. Write a macro with nested loops.
The outside loop is the quantity, such as For ItemQty = 1 to 100 (or to some other likely maximum).
The inside loops are the scenarios and nuances, such as For BoxesRecycled = 0 to 1. Each loop modifies the total, such as Total = Total - (BoxesRecycled * 0.15 * Total).
In the middle of all the loops is code that writes a line with the quantity, nuances, and total.
You will need to match the sequence in which charges and discounts were applied and the way the total was rounded. Probably the sequence was discounted 20%, then discounted 15%, then rounded. But maybe it was discounted 20%, then rounded, then discounted 15%, then rounded. If you don't match the sequence and rounding, then your total might be 1 cent different from an actual invoice.

Related

How to calculate prices in near calculation

I would like to calculate the prices in IQD. 1 USD is equal to 1458 IQD today.
There are 250, 500, 1,000, 5,000, 10,000, 25,000 and 50,000 denominations.
I need to sell my items based on USD. I have multicurrency plugin in my website. But it exchanges so precisely. It calculates smaller than cents.
For example, if I sell an item costs 1 dollar, the buyer need to pay 1458 IQD.
Is there anyway to calculate the prices what so called “near calculation”? Like, if an item costs 6820 it automatically shows 7000 at the checkout page. Or if it costs 6760, then shows 6750.
Thanks for your response.
unfortunately, there is no option in the plugin to do so.

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.

FV and PV formula's in Excel

I'm trying to calculate a lifetime value of a customer. Let's assume a new customer pays $100K per year and stays for 5 years. Let's discount any future years' payments with 10% rate.
This is manual calculation:
Year 1 $100,000.00
Year 2 $90,000.00
Year 3 $81,000.00
Year 4 $72,900.00
Year 5 $65,610.00
---------------------
Total $409,510.00
I can get the same value by using FV with negative rate.
FV(-0.1,5,-100000,0,0) = $409,510.00
What I'm trying to do is to get the same value using PV. And it's not exactly the same:
PV(0.1,5,-100000,0,1) = $416,986.54
I'm not sure what am I missing here. Does MS Office Excel 2010 PV understand discounting differently?
If you calculate out what PV is doing manually, the formula is actually this, for each individual year:
=Base Amount / (1 + Discount Rate) ^ Periods
Vs what FV is doing manually, the formula is this (which you seem to know based on coming to the same answer in your data):
=Base Amount * (1 - Discount Rate) ^ Periods
The reason for the difference in calculation is the mathematical difference between the two items - for background see here: http://www.investopedia.com/walkthrough/corporate-finance/3/time-value-money/future-value.aspx and here: http://www.investopedia.com/walkthrough/corporate-finance/3/time-value-money/present-value-discounting.aspx.
In short, if you have $100k today, and invest it in something which gives you 10% each year, then each year you add 10% of the current balance to get the new balance. ie: in year 1 you add 100k * 10% = 10k, giving a new total of 110k; in year 2 you add 110k * 10% = 11k, giving a new total of 121k, etc. - Mathematically, each year's amount is given by the formula listed above for the FV calculation.
Where this gets tricky is that you are giving yourself a negative interest rate - meaning every year, the value is decreasing each year by 10%. You have attempted to use the FV calculation with a negative interest rate, but that's not quite correct. What you should be using is the PV formula.
For the PV formula, if you know that you will receive 100k each year, you need to determine how much cash you would have needed originally, in order to earn the same amount - that is the present value of the cash flow stream. Now, you need to 'gross-up' the value of each year's income stream. The formula for this gross-up is derived mathematically and results in what I have above there for PV. Think about it like this - if there's a shirt that normally costs $100 and is now 30% off, you can see that you simply multiply it by 30%, to get $70. But if you see of shirt on sale for $70, and it's 30% off, then to determine the original base price you need to take $70 & divide by .3 - which gives us $100.
To prove to yourself that the PV formula is appropriate, take the income stream of, say, year 4 [3 periods of interest later, assuming first payment is received in day 0]: 100k / (1 + 10%)^3 = $75,131. Now, work backwards - if you want to know the future value of a $75k investment held for 3 periods of interest compounded annually with a 10% annual rate, you go: 75,131 * (1 + 10%) ^ 3 = 100k.
This is an important financial distinction, and you should read over the sources I've linked to ensure you understand it.
There is a difference in the calculation. FV takes 100,000 and discounts it by 10% to the number X so that X is 90% of the original value (i.e. X=90,000). PV by contrast discounts it to the number X such that 100,000 is 10% more than X. Quick math says X will be 10/11 of 100,000, i.e. 90909.09.
Indeed, if we apply this calculation 5 times:
Year 1 $100,000.00
Year 2 $90,909.09
Year 3 $82,644.63
Year 4 $75,131.48
Year 5 $68,301.35
---------------------
Total $416,986.5
I don't know if there is a way to make them behave the same way (I don't think there is, as they're calculating different things), but since FV solves your problem why not just use that?

simulation of subscription service in excel

Assuming there are 20 times on a month that a bus with a capacity of 8 drives from A to B and that there are Y subscriptions for the bus service, how does one simulate the events of people wanting to take a bus at a certain day exceeding the capacity of the bus? Knowing that on average a person would take the bus X times per month?
How do you translate the people on average taking the bus X times per month to a distribution of how many people will take the bus on a certain day?
I'll assume that the demand is constant for each customer, independent from trip to trip, and that customers are independent of each other and travel individually (no groups). Under those assumptions, if customer k has an average rate of nk trips per month, and a month contains 20 trips, there is a probability pk = nk / 20 that that customer will want to go on any particular trip. For each of the Y customers generate U, a Uniform(0,1) random number. If U <= pk, add this customer to that day's total demand. Finally, create an indicator variable E: if the total demand exceeds 8, E = 1, otherwise E = 0. Lather, rinse, repeat for as many days as you want to study. The average of the E's is an estimate of the proportion of trips for which demand exceeded capacity.

Monte Carlo Simulation using Excel Solver

I am trying to figure out what the optimal number of products I should make per day are, displaying the values in a chart and then using the chart to find the optimal number of products to make per day.
Cost of production: $4
Sold for: $12
Leftovers sold for $1
So the ideal profit for a product is $8, but it could be -$3 if it's left over at the end of the day.
The daily demand of sales has a mean of 150 and a standard deviation of 30.
I have been able to generate a list of random numbers using to generate a list of how many products: NORMINV(RAND(),mean,std_dev)
but I don't know where to go from here to figure out the amount sold from the amount of products made that day.
The number sold on a given day is min(# produced, daily demand).
ADDENDUM
The decision variable is a choice you make: "I will produce 150 each day", or "I will produce 145 each day". You told us in the problem statement that daily demand is a random outcome with a mean of 150 and a SD of 30. Let's say you go with producing 150, the mean of demand. Since it's the mean of a symmetric distribution, half the time you will sell everything you made and have no losses, but in most of those cases you actually could have sold more and made more money. You can't sell products you didn't make, so your profit is capped at selling 150 on those days. The other half of the time, you won't sell all 150 and will take a loss on the unsold items, reducing your profit a bit. The actual profit on any given day is a random variable, because it is determined by random demand.
Since profit is random, you can calculate your average earnings across many days based on the assumption that you produce 150. You can also average earnings based on the assumption that you produce 140 per day, or 160 per day, or any other number. It sounds like you've been asked to plot those average earnings versus how many you decided to produce, and choose a production level that results in the highest long-term average earnings.

Resources