I have a moving average with data points on everyday base e.g. 14 days MA.
Now I want to take this MA and display it on a bar chart e.g. one bar represents a week.
How I calculate the MA for this bar?
Is it the sum of the daily MA points over the week?
1,2,3,4,5,6,7
So the MA is 28? but the base is still daily?
Can someone try to explain if this makes sense and is correct?
Yes, Moving Average (MA) for the bar is the average of daily MA (daily count).
So
# Calculating MA
MA(week1) = (MA1 + MA2 + MA3 + MA4 + MA5 + MA6 + MA7)/7
MA(week1) = (1 + 2 + 3 + 4 + 5 + 6 + 7)/7 = 4
# Bar value 4
Incase your data is 14-day MA, you will have to make some assumptions and calculate the weekly MA. Have a look at the example to get a better understanding.
# 14-day MA -> Weekly MA
(W1 + W2)/2 = MA1
(W2 + W3)/2 = MA2
...
(Wn-1 + Wn)/2 = MAn-1
# Assume W1 == W2, you can estimate the per weekly MA
Example to calculate Moving Average
Related
Please how can i increase or decrease the value of a variable or parameter over a period of time generated using an ordered set? 1-24 hours.
I am modelling the charging and discharging of electric vehicles and I need to increase or decrease the State of charge SOC(battery level) after every period (depending on whether it is charging or discharging).
I have tried several methods but it isn't working. Also will it be best to model the battery level as a parameter or variable? I am trying to minimize the cost of customers charging their vehicles while also ensuring they get the maximum charge needed. Here is a snippet of my code.
Objective function is minimize( ∑Cost of charging -∑cost of discharging +∑Cost of unfulfilled charge)
isoc is initial state of charge
fsoc is final or expected state of charge
v1 = vehicle 1
v2 = vehicle 2
Set
t 'hours' / 1*10 /
i 'number of vehicles' / v1*v2 /;
Table vehdata(i,*) 'Vehicle characteristics'
at dt isoc fsoc
v1 1 8 4 50
v2 3 6 6 70
Scalar charging_power 'Charging power at station' / 6.6 /;
*Energy cost in dollars per kWh
Parameter energy_cost(t) / 1 0.03, 2 0.028, 3 0.025, 4 0.025, 5 0.026, 6 0.028,
7 0.041, 8 0.051, 9 0.048, 10 0.047 /;
Variable
Icharge(i,t)'charging decision'
Idischarge(i,t)'discharging decision'
z 'total cost of charging'
soc(i,t) 'State of charge'
Binary Variable Icharge, Idischarge;
soc.lo(i,t) = vehdata(i,"isoc");
soc.up(i,t) = vehdata(i,"fsoc");
Equation
costCharging 'define objective function'
soc_const1(i,t) 'Charging or discharging only takes place between arrival and departure'
soc_const2(i,t) 'SOC cannot charge and discharge at same time'
soc_const3(i,t) 'Increase or decrease state of charge after every period';
costCharging.. z =e= sum((i,t), (Icharge(i,t)*energy_cost(t) * charging_power)) -sum((i,t),(Idischarge(i,t)*energy_cost(t) * charging_power)) + sum((i,t), (vehdata(i,"tsoc") - soc(i, t))* energy_cost(t));
soc_const1(i,t).. Icharge(i,t) =e= 0$(vehdata(i,"at")> ord(t) and vehdata(i,"dt")< ord(t));
soc_const2(i,t).. Icharge(i,t) + Idischarge(i,t) =e= 1;
soc_const3(i,t).. soc(i,t) =e= soc(i,t+1) + (Icharge(i,t) * charging_power) - (Idischarge(i,t) * charging_power) ;
Model op_charging / all /;
solve op_charging using mip minimizing z;
display soc.l;
Firstful your model has some errors based on given. You should add ";" end of table vehdata like "v2 3 6 6 70;". Also, I think you want that the first constraint works on "at" and "dt" for each vehicle. Therefore I change it like:
soc_const1(i,t)$(vehdata(i,"at") = ord(t) or vehdata(i,"dt") = ord(t)).. Icharge(i,t) =e= 0;
Now you have a working model. But I think that it has logical errors. Therefore you should work on constraints.
The following formula in my SELECT text yields the aforementioned error when attempting to refresh.
SELECT CAPCSQ/((((ih01su + ih02su + ih03su + ih04su + ih05su + ih06su + ih07su + ih08su + ih09su + ih10su + ih11su + ih12su)/12)*1.32)/2)
The ih01su.... portion represents the last 12 months of sales data, divided by 12 to get an average. I then multiply by the 1.32 to get a projection of future sales in roughly 2 years based on store growth. I then divided by 2 because I really only want the value that will be 2 weeks worth of sales, not a full month.
The formula works fine until I attempt to divide the ‘CAPCSQ’ column by this calculated value. At this point I get the following error:
The maximum number of stacked diagnostics areas has been exceeded.
i am new here, I am using MERRA monthly solar radiation data. I want to convert w/M^2 to MJ/m^2
I am bit confused, how to convert solar radiation monthly average data W/m^2 to MJ/m^2
so far i understood by reading different sources,
Firstly i have to convert w/m^2 to kw/m^2
after kw/m^2 to mj/m^2 .......
Am i doing correctly
Just i am taking one instance:
For may month i have value 294 w/m^2
So 294 * 0.001 = 0.294 kw/m^2
0.294 * 24 (kw to kwh (m^/day)) = 7.056 kwh/m^2/day
7.056 * 3.6 (kwh to mj) = 25.40 mj/day
i am confused i am doing right or wrong .
Not sure why you would take the kWh step in between.
Your panels do 294 Watt per m², i.e. 294 Joule per sec per m². So that's 24*60*60 * 294 = 25401600 Joule per m² per day, or 25.4016 MJ per m² per day.
So if:
1 W/m2 = 1 J/m2 s
Then:
294 W/m2 = 294 J/m2 s
if you want it in days then:
1 day = 60s * 60min *24h = 86400s
294 J/m2 s x 86000s/1day = 25284000 J/m2 day
25284000 J/m2 day x 1MJ/1000000J = 25.284 MJ/m2 day
all together:
294 W/m2 = 294/(1000000/86400) = 25.4016 MJ/m2 day
A watt is the unit of power and Joules are the units of energy, they are related by time. 1 watt is 1 Joule per second 1W = 1 J/s. So the extension of that equation is that 1J = 1w x 1second. 1J = 1Ws. A loose analogy is if you say Litre is a unit of volume and L/S is a unit of flow. So your calculation needs to consider how long you are gathering the solar energy. So the number of Joules, if the sunlight shines at 90degrees to the solar panel for 1 hour is 294W/m2 x 3600s and would give ~1 x 10^7 joules per square metre. Of course as the inclination [the angle of light] varies away from 90 degrees, this will cause the effective power and hence the energy absorbed to drop, as a function of the sine of the angle to the sun. 90 degrees gives a sine of 1 and is full power.
My question is based on building a ramp up for planning production lines.
I have a WIP where a ramp up category is selected to be used for each MSO (Master Sew Order). The Ramp up is based on hour fences (for example 1-6 hours,6-12 hours,etc).
On the WIP, an MSO will have units (example 1,920 units), divided by capacity per hour (80 pcs/hr), to give time needed 24 hours. This then needs to be
calculated based on ramp up, for hours 1-6, 6-12, 12-18, and 18-24 and multiply our by related efficiency.
For example:
Hours 1-6: 20% efficiency * 80 units = 16 units/hr (6 x 16 = 96 units produced)
Hours 6-12: 40% efficiency * 80 units = 32 units/hr (192 units)
Hours 12-18: 60% efficiency * 80 Units = 48 units/hr (288 units)
Hours 18-24: 80% efficiency * 80 units = 64 units/hr (384 units)
Hours 24+: 100% efficiency * 80 units = 80 units/hr ((1920-960)/80)= 12 hours remaining
TOTAL TIME = 36 hours to produce
How would Power BI know to divide up the original 24 hour estimate into parts, multiply by respective efficiency, and return a new result of 36 hours?
Thank you so much in advance!
Kurt
Relationships
I'm not sure how to do this in DAX but you tagged PowerQuery so here's a custom query that computes 36 based on your parameters:
let
MSO = 1920,
Capacity = 80,
Efficiency = {
{6, 0.2},
{12, 0.4},
{18, 0.6},
{24, 0.8},
{#infinity, 1.0}
},
Accumulated = List.Accumulate(Efficiency, [
Remaining = MSO,
RunningHours = 0
], (state, current) =>
let
until = current{0},
eff = current{1},
currentCapacity = eff * Capacity,
RemainingHours = state[Remaining] / currentCapacity,
CappedHours = List.Min({RemainingHours, until - state[RunningHours]})
in [
Remaining = state[Remaining] - currentCapacity * CappedHours,
RunningHours = state[RunningHours] + CappedHours
]),
Result = if Accumulated[Remaining] = 0
then Accumulated[RunningHours]
else error "Not enough time to finish!"
in
Result
The inner lists for Efficiency are of the form time-efficiency-ends,efficiency-value. Plug in infinity to mean the last efficiency never stops.
In a normal iterative programming language you could update state with a for-loop, but in M you need to use List.Accumulate and package all your state into one value.
In your data model you may have MSO in one table containing 2 fields, [Units] and [UnitsPerHour], and another table called EffTable which may store the efficiencies broken out by the hour fences.
Create 4 new calculated columns in your MSO table, one for each hour fence, eg [1--6]:
=
6 * LOOKUPVALUE ( EffTable[Efficiency], EffTable[Hours], "1--6" )
* [UnitsPerHour]
These are fields that hold how many units you would produce in the 4 time slots. Create a new calculated field for the total, [RampUpUnits]:
=
[1--6Hours] + [6--12Hours] + [12--18Hours] + [18--24Hours]
Finally calculate the total time as:
=
24
+ ( [Units] - [RampUpUnits] )
/ [UnitsPerHour]
This calculates the number of hours required for the remaining units and adds it to 24 for the ramp up time.
Hi I'm currently trying to setup a Calculator for Rental Cars.
You'll put in the car category, the rental days, whether or not you want to book the fuel-flat and how many kilometers you'll travel, whether or not you'll need winter tires, if you're traveling to a certain destination and how many people will be in the car.
My Data-Spreadsheet currently looks like this:
http://i.imgur.com/P2kz6ts.png
So, if you would for example wanted to rent a Ford Fiesta for 2 days with 2 people, winter tires and fuel-flat for 80km to destination 2.
The calculator should now pick the price for 1-3 days and multiply it by 2 for two days.
To that the cost for winter tires will be added which are 3€ per day. Then it'll add the cost for the fuel-flat for 50 - 150 km, since you'll be traveling 80km. Since you're travveling to destination 2, the rental company is willing to give a discount of 15€. Finally the calculated cost will be divided by 2, since 2 people will rent the car and split the costs evenly.
That Calculation should look like this:
((30*2+(3*2)+13,80)-15)/2)
So in the End the total Cost of 32,4€ shall be displayed in a msgbox.
Now, how do i code that if the rental days are between 1-3, excel should take the values of that specific collumn and use it to calculate the cost. Moreover, if you're renting the car more than a week then the price for 6-7 days shall be used and additional days be added according to the category.
Problem fixed, look at the Answer.
Here's the code that fixed the Problem:
If rentaldays > 30 Then
Application.Cells(3, 3).Value = "You're trying to rent a Car for more than 30 Days. Please use the longterm program."
price = 0
End If
If rentaldays = 30 Then
monat = (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 7, False))
End If
If rentaldays > 7 Then
zusatz = price + (((rentaldays - 7) * Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 6, False)))
rentaldays = rentaldays - (rentaldays - 7)
End If
If rentaldays = 6 Or rentaldays = 7 Then
woche = (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 5, False))
End If
If rentaldays > 3 And rentaldays <= 5 Then
tage = price + (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 4, False) * rentaldays)
End If
If rentaldays >= 1 And rentaldays <= 3 Then
tage = price + (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 3, False) * rentaldays)
End If
You need to make this easier , not "smarter"
Just add more columns!
Then you have 3 simple rules (english code)
if days >= 30 then
price = Col K 'lookup for car
days = days - 30
end if
if days > 7 then
price = price + ((days - 7) * Col J) 'lookup for car
days = days - (days - 7)
end if
if days > 0 then
price = price + hlookup( days, C:I .....) 'lookup for car
end if