Dynamic Range for Average Calculation - excel-formula

I am trying to come up with an Excel Formula to calculate 6 Months average value from Monthly prices.
A year is considered from April 2022 to March 2023 and so on. That means from April 2022 to Sept 2022 it is Half 1 and Oct 2022 to Mar 2023 it is Half 2.
Total time line is till March 2055. So, the formula has to be dynamic.
Please advise how I can use a formula for this averaging task.
The Data table look like below.
INPUT
Please refer the link to picture
OUTPUT
In Yellow in the picture below
Table Pic
Thank you!

It would be fairly simple if we had 'regular' half-year periods. Since half-years are shifted 3 months forward, we also need to shift the formula by three months. To achieve that, we have an OFFSET function that we can apply for the prices row. It will work fine for all the half-year periods with the exception of the first one since we'll have the prices range shifted. So, for the first half of 2022 in the cell B9 we will simply write =AVERAGE(B5:G5) and for all the rest, starting from C9, -
=AVERAGEIFS(OFFSET($B$5:$OG$5,0,3),$B$1:$OG$1,C7,$B$2:$OG$2, IF(C8=1,"<="&6,">"&6))
assuming that the months start in column B like in your example picture and finish in column OG as suggested from your task description.

If you want rolling 6mo periods, I prefer INDIRECT to OFFSET.
Assume the data runs vertically, each month is a separate row, and "X" is the cell of the latest value, this should work:
=AVERAGE(INDIRECT(ADDRESS(ROW(x), COLUMN(X))&":"&ADDRESS(ROW(X)-5, COLUMN(X))))

Related

How to count unique days in excel after autofiltering

I have a sheet where I would like to count the unique days. What I mean by that is, the data covers 1 Jan 2017 to 31 Dec 2017, but not all dates are included. When autofiltered, even less days are showing. I have tried many different formulas I have been given, but they all fall over when the sheet is autofiltered for the required criteria. The closest one was an array formula, entered in Excel for Mac 16.43. It was entered using Ctrl & Shift & Enter
=SUM(IFERROR(IF(FREQUENCY(A3:A5524,A3:A5524),IF(SUBTOTAL(3,OFFSET(A3:A5524,ROW(A3:A5524)-ROW(A3),0,1)),1)),0))
It counts the correct number of days when the sheet is unfiltered, the number changes as the sheet is autofiltered, but again becomes incorrect when this is done. There might be a date range showing of 6 Jan 2017 to 20 June 2017, but only have 75 actual days showing in that range; nothing I have yet tried can get it accurate after autofiltering
The data is laid out in a pretty standard way with column A being date and it is formatted as Date and dd/mm/yyyy
Hopefully someone can suggest something which works
The answer ended up being the following
=SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(A3:A5524,ROW(A3:A5524)-ROW(A3),0,1)),A3:A5524),A3:A5524),1))
Rather than the original formula
cheers
Array formula
=COUNT(0/FREQUENCY(IF(SUBTOTAL(2,OFFSET(A2,ROW(1:5522),)),MATCH(A3:A5524,A3:A5524,),),ROW(1:5555)))
Note parameter, if column A is a date, the use of 2, if column A is text, using a 3, but FREQUENCY unavailable.

MS Excel: Moving average last 12 months for each expenses (with the current date)

I would like to know what is the formula to know the average cost of the last 12 months for each expenses that I have with the current month and that keeps the last 12 months average as the months go by?
To be more precise and for example: now we are in January 2021, I would like to know the average cost from January 2020 to December 2020 for INTERNET
Here's an image of the data:
Here's an image of the tab I want to enter the formula (in cell C2):
Thanks in advance for your response and let me know if my query is not clear enough. Have a good day/evening!
P.S.Sorry for those who can't read french, the file is in french but the dates are formatted in english and for the cost column, it's pretty much universal . I've modified the average column in english (column C in "Budget" tab) to let you know where I want to put the formula.
Use AVERAGEIFS with EDATE:
=AVERAGEIFS('Despenses'!E:E,'Despenses'!G:G,A2,'Despenses'!C:C,">="&EDATE(EOMONTH(TODAY(),-1)+1,-12))

Dynamic SumIFs - Multiple Scenarios

I have a headcount data structured in the following way.
Data Structure:
Every month I append one dataset to another by pasting values in the first empty row in one main sheet.
1a. Therefore, one employee can be included in the sheet for more than one time.
There is a column that tells me if the person left the company this month or if he got hired.
I want to have an executive summary with a comparison of two months. I managed to have this working with a static data month over month (so for instance to have a walk from July to August, October to November, etc.) with using countifs.
Question:
I would like to have a dynamic selection in my summary sheet.
if I select January in one cell and September in another, the formulas will calculate how many hires and leavers were there from January until September.
If I select February in once cell and July in another, the formulas will calculate how many hires and leavers were there starting from February until July.
This is the exact formula I have for calculating Month Over Month change: =COUNTIFS(SSE_Reporting!$R:$R,MoM_Walk!$A5,SSE_Reporting!$AH:$AH,MoM_Walk!H$4,SSE_Reporting!$AK:$AK,MoM_Walk!U$1)
Please keep in mind below:
My dataset contains information starting January 2019 until today (and will be increased)
In the executive summary, I may want just to have the view from March 2019 until December 2019 (therefore, in this case, countifs will not work, because it will count either ALL leavers or just leavers for ONE specific month)
You could do a COUNTIFS to count how many Leaver/Hire you got in a given date range.
Something like this could guide you to deploy your own formula:
My formula in H4 is:
=COUNTIFS($A$2:$A$28;H$3;$B$2:$B$28;">="&$F4;$B$2:$B$28;"<="&$G4)
As you can see, it works perfectly to count the criteria on multiple given date ranges.
COUNTIFS
function

First two Months Blank and then calculate average

I have three columns "Month Name" "Team" and "Mismatch%
I have 8 months of data for each and I am trying to calculate 3 months rolling average as shown in the below table.
Every time the team changes the first two months should be blank as shown in the image. Currently I have data from Fiscal Month June to January hence June and July should be blank. If i have data from Fiscal month July to Feb then July and August will be blank and so on.
enter image description here
enter image description here
I tried my luck using Offset and average function in excel. But did not get the desired results. If anyone could help me to write a condition or formula to keep first two months cell blank and then calculate average will be very helpful.
Awaiting your positive response!
Thanks,
G
Place this in cell D4 and copy down:
=IF(COUNTIF($B$2:B4,B4)<=2,"",AVERAGE(C2:C4))

Adding Sum based on the month criteria

I am planning to add a simple formula to calculate the sum for each individual based on month (i.e. cell C14). If I change the month to March, then sum should be taken from Jan to Mar and if I change the month to December, then sum should be taken from Jan to Dec for that particular person.
I am currently using the follwoing formula, but it is coming too big. I have just added from Jan to Apr only and it is coming this long. I don't want such a big formula. Is it possible to change it to very simple formula?
=IF(C14="Jan",VLOOKUP(A17,$A$3:$M$11,2,0),IF(C14="Feb",VLOOKUP(A17,$A$3:$M$11,2,0)+VLOOKUP(A17,$A$3:$M$11,3,0),IF(C14="Mar",VLOOKUP(A17,$A$3:$M$11,2,0)+VLOOKUP(A17,$A$3:$M$11,3,0)+VLOOKUP(A17,$A$3:$M$11,4,0),IF(C14="Apr",VLOOKUP(A17,$A$3:$M$11,2,0)+VLOOKUP(A17,$A$3:$M$11,3,0)+VLOOKUP(A17,$A$3:$M$11,4,0)+VLOOKUP(A17,$A$3:$M$11,5,0)))))
Try this
B17: =SUM(OFFSET($A$2,MATCH(A17,$A$3:$A$11,0),1,1,MATCH($C$14,$B$2:$M$2,0)))
and fill down as needed.
I'm not sure if I can come up with a non-volatile formula.
In the above, we use the MATCH function to compute both the row offset into the table; as well as the width of the returned array.

Resources