Excel - How to do the following? - excel

I have a question related to EXCEL:
Since I have the following prices for different period, how can I compute in an automatic way, for example the price between 10 June - 15 July ?
EDIT--> Expected output:
50€+50€ (10-11 june) + 58€x13 (period 12 june - 25 June) + 75€x13 (period 26 june - 9 July) + 92€x5 (period 10 july-15july) = 2289€
This is the same pictures with the cells in excel, please do not consider the "Price of period", but only the daily price

You could do this with a (lengthy) calculation:
Consider:
A8 Contains the from date (10-06-2021)
B8 Contains the from date (17-07-2021)
=(MIN($B$8,D3)-MAX($A$8,C3)+1)*C5+(MIN($B$8,F3)-MAX($A$8,E3)+1)*E5+(MIN($B$8,H3)-MAX($A$8,G3)+1)*G5+(MIN($B$8,J3)-MAX($A$8,I3)+1)*I5
This will consider a period from 10-06 - 11-06 a period of 2 days. And also 12-06 - 25-06 a period of 14 days, and so on.
The result is: 2514.00

One method would be to create a lookup table and use a formula.
Given your data, your lookup table might as shown below:
I NAME'd it: priceTable
You can then use the formula:
=SUM(VLOOKUP(SEQUENCE(End-Start+1,,Start,1),priceTable,2))
If, for some reason, you cannot easily create priceTable, you can create it with a formula (depending on your version of Excel):
=INDEX($C$4:$I$6,{1,3},{1;3;5;7})
Note: All of the formulas assume your dates are real dates and not strings.
If your version of Excel does not have the SEQUENCE function, you can replace it with:
=SUM(VLOOKUP(ROW(INDEX($A:$A,Start):INDEX($A:$A,End)),priceTable,2))

Related

Google Sheets or Excel Function to return date based on value

I have this table in Google Sheets (or excel). The year is the two last digit of my code.
Code Duration Months
1 AC-26482-17 60
2 AC-26482-18 30
3
I would like to return the date in this format (If no data, just leave blanks).
Code Duration Months Start Expiration
1 AC-26482-17 60 01/01/2017 01/01/2022
2 AC-26482-18 30 01/01/2018 01/07/2020
3
Is there a way to achieve this?
You mean you want to add the duration in months to the start date? If so, your sample has the wrong expiration date. 30 months added to 1/1/2018 is not June 1st, but July 1st.
The formula in Excel is
=EDATE(C2,B2)
If you also want to calculate the start date from the last two characters of the code, given all dates are in this millennium, then you can use this for the start date:
=DATE(RIGHT(A2,2)+2000,1,1)
edit: To handle blank cells, you can check with IsBlank()
=if(isblank(a2),"",DATE(RIGHT(A2,2)+2000,1,1))
use:
=ARRAYFORMULA(IF(A2:A="",,DATE(IF(RIGHT(A2:A, 2)*1>=40,,20)&RIGHT(A2:A, 2), 1, 1)))
=ARRAYFORMULA(IF(A2:A="",,DATE(YEAR(C2:C), MONTH(C2:C)+B2:B, 1)))

How to find a trend/forecast result 14 days from today

I have looked into the Forcast & Trend formula but I cannot figure it out for the life of me.
I want to work out the trend 14 days from now.
I have a set of data:
A1 - A30 with dates
B1 - B30 with daily ticket count for the business.
I would like to make a result in another cell that would predict what the estimated total ticket count would be 14 days from now. I do not need all 14 days, just the 14th day.
If I was to try show you what the formula looks like in my head it would be:
=trend/forecast(B1:B30,14)
or
=Predict(B1:B30)*14
Unfortunately it is not as easy as that. How can I do this?
I think you want to use the Forecast function. The inputs you have do not match the correct format though.
FORECAST( x, known y's, known x's) where...
x = the series (or date) you want to forecast
known y's = historical tickets per day
known x's = historical dates (or series)
The below example allows you to forecast tickets for any date (Forecasted Date) given the historical information (table on left). If your table is not formatted with actual dates, just create a series (first day = 1, second day = 2, etc.) and forecast that way.
Given the historical data, the forecasted tickets for Aug 28th (14 days after last known value) are 16.7

How do I write an Excel formula to compare year-to-date to prior years & also account for leap years?

I’m trying to compare a measure as of today through the same day and month for the prior 4 years (e.g. through June 6 of 2016, 2015, 2014, etc.).
For each year, I decided to count the number of days since the beginning of the year, and sum my values through that number of days for each year.
To identify whether a date should be included in the year to date comparison, I used the formula where my date is in cell A1:
=IF((A1-DATE(YEAR(A1),1,1)+1)<=(TODAY()-DATE(YEAR(TODAY()),1,1)+1),1,0)
I’m looking for a way around the issue of the extra day added to leap years. In other words, after February 28th, the day count will always be off by one in a leap year, and trying to use Februrary 29th in a non-leap year will return an error.
I’d like to adjust this formula, but I’m open to using a different function & formula if it gets me the right results.
you can check any information about February, 29th. If an error occurs, you know its no leap year. Catch that error with =IFERROR(;).
Assuming a table structure like this:
A:Date | B:Value
----------------------
01/01/2016 | 0
01/01/2015 | 1
01/01/2014 | 2
01/01/2013 | 3
01/01/2012 | 4
Formula
To - for example - calculate the average of the previous four (excluding the current) years on January 1st (today is 01/01/2016):
=SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
(B:B)
) / (
SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
1
)
)
Result
For the above example, the result is 2.5
Explanation
To select only those rows representing the same month and day:
(MONTH(A:A)=MONTH(compare))*(DAY(A:A)=DAY(compare))
To select only those values from the previous 4 years (excluding the current):
(YEAR(A:A)>YEAR(compare)-5)*(YEAR(A:A)<YEAR(compare))*
The actual values we are interested in:
(B:B)
Divide by 4 for the average over the last four years. This assumes there is no missing data which might be an issue. You could use another SUMPRODUCT (replace B:B with 1) to count the number of resulting rows and divide by that number to handles this case. This seems to be rather slow, but it works.
Note
For performance reason you should not use A:A (a full column) in the formula, just use the actual range you need, which will likely be much faster.

Calculating the average difference in days within a period

I am trying to calculate the average difference between two columns in excel. The columns contain a planned and an actual date, I would like to get the average difference but only for planned dates within the last three months.
Example:
Planned Start Date | Actual Start Date
21/09/2013 | 25/09/2013
10/07/2014 | 16/07/2014
01/06/2014 | 30/06/2014
The formula should only take line 2 & 3 (line 1 is older than 3 months), look at the difference in days for each applicable line (line 2: 6 days, line 3: 29 days) and then show the average ( 17.5 days) of all applicable lines.
Does anybody have a formula for this? Excel really isn't my strong suit...
Assume your data is in A2:B4 then try this array formula
=AVERAGE(IF(TODAY()-A2:A4<=90,B2:B4-A2:A4))
It assumes each month is 30 days (hence the 90)
Press CTRL + SHIFT + ENTER to enter the formula as an array formula
Based on your example I get a result of 17.5 days.

MS Excel: Using AGGREGATE to add up all mileage in each month

I have the following data in a logbook format:
DATE MILEAGE
02-Jul-13 15
05-Jul-13 12
09-Jul-13 156
10-Aug-13 20
11-Aug-13 20
12-Aug-13 232
12-Aug-13 20
13-Aug-13 265
15-Aug-13 20
18-Aug-13 20
I am looking to extract data from it.
I need to ignore errors and #N/A so I have been trying to use the AGGREGATE function. To no avail though.
I would like to present the following information:
Mileage this month -
=AGGREGATE(9,7, IF(MONTH(IFERROR(LogBookTable[Date], 0)) = MONTH(TODAY()), LogBookTable[Total KM], 0)) - Does not work
Mileage in July -
=AGGREGATE(9,7, IF(MONTH(IFERROR(LogBookTable[Date], 0)) = MONTH(7), LogBookTable[Total KM], 0)) - Does not work
Mileage in August -
=AGGREGATE(9,7, IF(MONTH(IFERROR(LogBookTable[Date], 0)) = MONTH(8), LogBookTable[Total KM], 0)) - Does not work
Total Mileage -
=AGGREGATE(9,7,LogBookTable[Total KM]) - This works
The monthly mileage and current month mileage all result in a "#VALUE!" being displayed.
Any assistance would be much appreciated.
Just in case anyone asks, the naming schemes are corrected, it's not the references that aren't working, it's the values.
You could use DSUM. If you had two criteria cells setup Say in D1:E2 as follows:
Date Date
>1/07/2013 <31/7/2013
and if your data was in A1:B11 (as per your example above), to return a sum for July ignoring errors, use the following formula:
=DSUM(A1:B11,2,D1:E2)
You could setup the criteria such that they were updated based on the current month, and that the month end is calculated using:
="<"& DATE(YEAR(TODAY()),MONTH(TODAY())+1,DAY(1)-1)
and the month start calculated by:
=">"& DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(1))
Remember that with criteria, multiple criteria on the same row is an AND, and multiple rows on the same criteria is an OR.
You can use SUMIF is you add a column representing the month of the date:
Column B contains =MONTH of Column A. All you have to do is update the DATE entry in A16 with a new date. B16 is accordingly updated with the appropriate month, creating a new monthly aggregate/sum.

Resources