Creating a Variable Curve from Linear Data - excel

My end goal is to distribute items into different discounts for sales. For example I may have 1000 items in an up-to 20% off sale. I am trying to come up with a way to cluster more items towards a discount, say 15%. So the discount distribution is a curve, with the peak number of items around 15% and less items at the extreme low and high discounts.
I want this to work for many different sales- number of items included will change and the discount ranges will change. I may have 25,000 items in a 10-40% off sale.
Variables:
L = Low Discount
H = High Discount
S = Discount Spread (H - L)
I = Item Count
D = Discount Sread (S / I)
C = ClusterPeak, where I want the most items
All items are ranked and sorted. Using Excel, Excel VBA or FileMaker I am sure there is math thing I can throw at this to make work.
Using the first example of 1000 items in an up-to 20% off sale. (starting at 1%)
L = .01
H = .2
S = .19
I = 1000
D = .00019
C = .15
R = Current Row or Record.
To get linear, evenly distributed discounts, I know I can do this-
(R * S) + L or (1 * .00019) + .1
This gets me .01019, .01038... The 1000th item gets .2, or 20%. This works regardless of the discounts and items count. Yay!
But I am stumped on how to cluster more items around a discount in a smooth curve. I have tried throwing LOG and standard deviation at the problem in various uses but obivously it didn't work or I wouldn't be here.
Sorry if this is miscategorized or poorly explained. It is very hard explaning what you don't know. Is there a better name or description for what I am trying to accomplish?

Related

DAX. Problem with subtotals and grand totals

hope you are doing well and can help solve this puzzle in DAX for PowerBI and PowerPivot.
I'm having troubles with my measure in the subtotals and grand totals. My scene is the following:
I have 3 tables (I share a link below with a test file so you can see it and work there :robothappy:):
1) "Data" (where every register is a sold ticket from a bus company);
2) "Km" (where I have every possible track that the bus can do with their respective kilometer). Related to "Data";
3) and a "Calendar". Related to "Data".
In "Data" I have all the tickets sold from a period with their price, the track that the passenger bought and the departure time of that track.
Each track can have more than 1 departure time (we can call it a service) but only have a specific lenght in kilometers (their kilometers are specified in the "Km" table). 
Basically what I need is to calculate the revenue per kilometer for each service in a period (year, month, day).
The calculation should be, basically:
Sum of [Price] (each ticket sold in the period) / Sum of [Km] (of the period considerating the services with their respective kilometers)
I managed to calculate it for the day granularity with the following logic and measures:
Revenue = SUM(Data[Price])
Unique dates = DISTINCTCOUNT(Data[Date])
Revenue/Km = DIVIDE([Revenue]; SUM(Km[Km])*[Unique dates]; 0)
I created [Unique dates] to calculate it because I tried to managed the subtotals of track granularity taking into account that you can have more than 1 day with services within the period. For example:
For "Track 1" we have registered:
1 service on monday (lunes) at 5:00am.
Revenue = $1.140.
Km = 115.
Tickets = 6.
Revenue/Km = 1.140/115 = 9,91.
1 service on tuesday (martes) at 5:00am.
Revenue = $67.
Km = 115.
Tickets = 2.
Revenue/Km = 67/115 = 0,58.
"Subtotal Track 1" should be:
Revenue = 1.140 + 67 = 1.207.
Km = 115 + 115 = 230.
Tickets = 6 + 2 = 8.
Revenue/Km = 1.207/230 = 5,25.
So at that instance someone can think my formula worked, but the problem you can see it when I have more than 1 service per day, for example for Track 3. And also this impact in the grand total of march (marzo).
I understand that the problem is to calculate the correct kilometers for each track in each period. If you check the column "Sum[Km]" is also wrong.
Here is a table (excel file to download - tab "Goal") with the values that should appear: 
[goal] https://drive.google.com/file/d/1PMrc-IUnTz0354Ko6q3ZvkxEcnns1RFM/view?usp=sharing
[pbix sample file] https://drive.google.com/file/d/14NBM9a_Frib55fvL-2ybVMhxGXN5Vkf-/view?usp=sharing
Hope you can understand my problem. If you need more details please let me know.
Thank you very much in advance!!!
Andy.-
Delete "Sum of Km" - you should always write DAX measures instead.
Create a new measure for the km traveled:
Total Km =
SUMX (
SUMMARIZE (
Data,
Data[Track],
Data[Date],
Data[Time],
"Total_km", DISTINCT ( Data[Kilometers Column] )
),
[Total_km]
)
Then, change [Revenue/Km] measure:
Revenue/Km = DIVIDE([Revenue], [Total Km])
Result:
The measure correctly calculates km on both subtotal and total levels.
The way it works:
First, we use SUMMARIZE to group records by trips (where trip is a unique combination of track, date and time). Then, we add a column to the summary that contains km for each trip. Finally, we use SUMX to iterate the summary record by record, and sum up trip distances.
The solution should work, although I would recommend to give more thoughts to the data model design. You need to build a better star schema, or DAX will continue to be challenging. For example, I'd consider adding something like "Trip Id" to each record - it will be much easier to iterate over such ids instead of grouping records all the time. Also, more descriptive names can help make DAX clean (names like km[km] look a bit strange :)

Find a growth rate that creates values adding to a determined total

I am trying to create a forecast tool that shows a smooth growth rate over a determined number of steps while adding up to a determined value. We have variables tied to certain sales values and want to illustrate different growth patterns. I am looking for a formula that would help us to determine the values of each individual step.
as an example: say we wanted to illustrate 100 units sold, starting with sales of 19 units, over 4 months with an even growth rate we would need to have individual month sales of 19, 23, 27 and 31. We can find these values with a lot of trial and error, but I am hoping that there is a formula that I could use to automatically calculate the values.
We will have a starting value (current or last month sales), a total amount of sales that we want to illustrate, and a period of time that we want to evaluate -- so all I am missing is a way to determine the change needed between individual values.
This basically is a problem in sequences and series. If the starting sales number is a, the difference in sales numbers between consecutive months is d, and the number of months is n, then the total sales is
S = n/2 * [2*a + (n-1) * d]
In your example, a=19, n=4, and S=100, with d unknown. That equation is easy to solve for d, and we get
d = 2 * (S - a * n) / (n * (n - 1))
There are other ways to write that, of course. If you substitute your example values into that expression, you get d=4, so the sales values increase by 4 each month.
For excel you can use this formula:
=IF(D1<>"",(D1-1)*($B$1-$B$2*$B$3)/SUMPRODUCT(ROW($A$1:INDEX(A:A,$B$3-1)))+$B$2,"")
I would recommend using Excel.
This is simply a Y=mX+b equation.
Assuming you want a steady growth rate over a time with x periods you can use this formula to determine the slope of your line (growth rate - designated as 'm'). As long as you have your two data points (starting sales value & ending sales value) you can find 'm' using
m = (y2-y1) / (x2-x1)
That will calculate the slope. Y2 represents your final sales goal. Y1 represents your current sales level. X2 is your number of periods in the period of performance (so how many months are you giving to achieve the goal). X1 = 0 since it represents today which is time period 0.
Once you solve for 'm' this will plug into the formula y=mX+b. Your 'b' in this scenario will always be equal to your current sales level (this represents the y intercept).
Then all you have to do to calculate the new 'Y' which represents the sales level at any period by plugging in any X value you choose. So if you are in the first month, then x=1. If you are in the second month X=2. The 'm' & 'b' stay the same.
See the Excel template below which serves as a rudimentary model. The yellow boxes can be filled in by the user and the white boxes should be left as formulas.

Excel Formula, To Calcuate a maximum Weight based off a desired minimum profit (GP%)

So I am working on a spreadsheet for a Butchery I manage and have run into a problem.
First off back story: We do $20 packs for certain bulk products that have a min/max weight range.
The Goal is to be able to put in this spreadsheet the desired minimum GP% and from that get a maximum weight based off that minimum profit margin.
For example a Beef Steak that Costs $17.50 p/kilo Would be minimum of 680g (at a GP% of 30.30%) and a maximum weight of 790g (at a GP% of 20.50%)
I have been 'googling' all day, and banging my head on my desk (as well as experimenting with different formula's) I am starting to think I may have to resort to programming a macro to perform this but I would prefer to be able to achieve in a formula on the cell that way I can copy-paste easily down the spreadsheet.
If anyone has a solution or can put me on the right track would be Awesome.
I think the formula you are looking for is :
your selling price (=20$) / your mark up on cost
where your mark up is :
your cost per kilo / (1- your margin)
So for 20% expected GP it gives :
= 20 / (17.5 / (1-0.2))
= 20 / 21.875
= 0.914... kilos
Balance is then :
Revenue = 20$
Cost = 0.914 * 17.5 = 16
Margin = 4
Margin % = 20

Computing sum of progressively-increasing values in Excel

I am trying to solve an iterative problem in Excel. I want to be able to calculate the sum of rent for x years. The rent is increasing at a rate of 10 percent every year. I quickly came up with this python code on a REPL for clarity:
year = 6
rent = 192000
total_rent = rent
for x in range(1 , year):
rent= rent + .1*rent
total_rent = total_rent + rent
print(total_rent) # 1481397.12 is what it prints
This is a trivial problem in programming but I am not sure the best way to achieve this in excel.
In excel I am doing it this something like this:
But all the intermediate rent amount(s) are not really needed. I guess there should be a for loop here as well too, but is there a mathematical representation of this problem which I can use to create the expected result?
If you have a financial problem, you might try the financial functions of excel.
=-FV(0.1, 6, 192000)
or
=FV(0.1, 6, -192000)
the detail: FV on Office Support
Description
FV, one of the financial functions, calculates the future value of an investment based on a constant interest rate. You can use FV with either periodic, constant payments, or a single lump sum payment.
Syntax
FV(rate, nper, pmt, [pv], [type])
For a more complete description of the arguments in FV and for more information on annuity functions, see PV.
The FV function syntax has the following arguments:
Rate Required
The interest rate per period.
Nper Required
The total number of payment periods in an annuity.
Pmt Required
The payment made each period; it cannot change over the life of the annuity. Typically, pmt contains principal and interest but no other fees or taxes. If pmt is omitted, you must include the pv argument.
Pv Optional
The present value, or the lump-sum amount that a series of future payments is worth right now. If pv is omitted, it is assumed to be 0 (zero), and you must include the pmt argument.
Type Optional
The number 0 or 1 and indicates when payments are due. If type is omitted, it is assumed to be 0.
Your problem is a geometric series where the initial term is a = 192000 and the common ratio is r = 1.1. (The ratio is not just the 10% added, it includes the 100% that is added to.) To refresh your Algebra II memory, a geometric series is
total = a + a*r + a*r**2 + ... + a*r**(n-1)
The closed-form formula for the sum of the geometric series is
total = a * (r**n - 1) / (r - 1)
(using Python syntax), or, using something closer to Excel syntax,
total = a * (r^n - 1) / (r - 1)
where n is the number of years. Just substitute your values for a, r, and n.
As the question is about excel it is possible by
Or by using the FV function.
FV returns the future value of an investment based on regular payments and a constant interest rate.
Attributes of the FV function;:
Rate: The interest rate per period.
Nper: The total number of payment periods in an annuity.
Pmt: The payment made each period; it cannot change over the life of the annuity. Typically, pmt contains principal and interest but no other fees or taxes. If pmt is omitted, you must include the pv argument.
Pv: The present value, or the lump-sum amount that a series of future payments is worth right now. If pv is omitted, it is assumed to be 0 (zero), and you must include the pmt argument.
Type: The number 0 or 1 and indicates when payments are due. If type is omitted, it is assumed to be 0.
Yet another way is computing it as a geometric series with the non-financial function SERIESSUM:
=SERIESSUM(1.1,0,1,192000*{1,1,1,1,1,1})
The rate multiplier is 1.1, starting from 1.1^0 == 1 and increasing by 1 each year. The result is 1*a + 1.1*b + 1.1^2*c.... The array 192000*{1,1,...} provides the coefficients a, b, c, ... : one array value for the initial total_rent = rent, and one for each subsequent year 1..5 (from range(1,year)).

Excel Function to Determine Optimal Price

I need help creating an Excel function that will determine the optimal price-point for a product, given the required profit margin.
NET MARGIN = (PROFIT / PRICE) = 30%
PRICE = (COGS + Fixed Costs + Variable Costs)
COGS = $5.00
FIXED = $3.00
VARIABLE = (15% * PRICE)
The problem that I can't get my head around is that as the price goes up, the variable costs go up as well. So how do I automate the product pricing for a required margin of 30%?
Any help is appreciated.

Resources