I want to create a SUMIFS formula with a date criteria. The whole report is based on years and weeknumers and I like to keep it that way without converting these to dates. The data is set up as following:
Col A Col B Col C Col D
YEAR Weeknumber Turnover ColA & ColB
I want to create a MAT turnover number based on the report week and year. I tried to merge colums A & B to get YYYYWW but since the first 9 weeks are only one digit the formula does not work.
note Cel F1 contains the report year and Cel F2 contains the report week
The sumif formula is the folowing:
=SUMIFS(C:C;D:D;"<="&F1&F2;D:D;">="&(F1-1)&F2)
Anyone got any idea how I can make this work?
So your column D formula:
=--(A1&TEXT(B1,"00"))
Your other formula:
=SUMIFS(C:C,D:D,"<=" & --(F1 & TEXT(F2,"00")),D:D,">=" & --(F1-1 & TEXT(F2,"00")))
If you want to do it all with one formula then:
=SUM(IF(( --(F1 & TEXT(F2,"00"))>=--(A:A &TEXT(B:B,"00")))*( --(F1-1 & TEXT(F2,"00"))<=--(A:A &TEXT(B:B,"00"))),C:C))
This is an array formula and needs to be confirmed with Ctrl-Shift-Enter when leaving edit mode.
This is slow as it is written. It would be best if all the full column references were truncated to just the extreme absolute data limit. As in A:A to $A$1:$A$10000. This will speed up the array formula.
Related
I have an excel sheet where I need to take an average cost of 7 days. I have two columns, one with a date and the other with a charge. See the attached screenshot for reference and output. The formula I'm using for charges works as expected in column d. I need to find a way to add the date range in column c. Please advise
Date: Need help here - Column c should repeat, and the next cell should have 2022-08-02 and 2022-14-02. The current formula starts on 2022-02-02 if I drag the cell.
Try below formula to google-sheet.
=INDEX(TEXT(A2+SEQUENCE(10,1,0,7),"yyyy-dd-mm") & " " & TEXT(A2+SEQUENCE(10,1,6,7),"yyyy-dd-mm"))
For Excel-365 no need INDEX().
=TEXT(A2+SEQUENCE(10,1,0,7),"yyyy-dd-mm") & " " & TEXT(A2+SEQUENCE(10,1,6,7),"yyyy-dd-mm")
I'm trying to average the most recent 6 values of 'x' - however, I'm getting reference errors when trying to average them. The value I'm looking for should be 8,720.33 with the criteria of 'x'. The dates have no bearing in the formula, just a visual reference point.
Formula I'm getting lost on "=AVERAGE(OFFSET(INDEX(C2:C42,MATCH(E2,B2:B42,0),),0,0,-6))"
*Note - the dates are being updated daily to include historical data points
Data Set:
You can try following array formula:
=AVERAGE(INDEX(C1:C25,N(IF(1,AGGREGATE(14,6,ROW(A1:A25)/(B1:B25=E2),ROW(A1:A6)),0))))
or with full ranges:
=AVERAGE(INDEX(C:C,N(IF(1,AGGREGATE(14,6,ROW(A:A)/(B:B=E2),ROW(A1:A6)),0))))
Confirm it with ctrl + shift + enter
You might be able to pull this off with AVERAGEIFS if you add a rank column that ranks Header1 by date.
In my example:
Column D is the Values you are averaging
Column B is Hearder1
Column C is the rank - =COUNTIFS($B:$B,B2,$A:$A,">"&A2)+1
=AVERAGEIFS($D:$D, $B:$B, "x", $C:$C, "<7")
I have the following Excel spreadsheet:
A B C D E F G
1 Year 2015 2016 2017 2018 2019 2020
2 Revenue 5.000 4.000 6.000
3 Years to go back: 2
4 Sum of Periods: 10.000
In Row 1 you can find the years 2015 til 2020 and in Row 2 the corresponding revenue of each year.
In Cell C3 the user should input the number of years to go back and sum up the revenues. For example if the user puts in a 2 Excel goes back 2 years and sums up the revenue of 2017 and 2016 which is 10.000 in the case above. For this I used the following formula:
=SUM(OFFSET($E$2,0,-C3):$E$2)
This formula and the described calculation above work perfectly so far.
However, in 2018 I will have to adjust the starting point of Cell $E$2 in the formula above to Cell $F$2. Ohterwise the year 2018 will be excluded from the calculation.
=SUM(OFFSET($F$2,0,-C3):$F$2)
My question is now how can I avoid this permanent re-adjustment every year?
--> I think the solution should be a formula that identifies the first "non empty" cell within in a Row and then starts counting back the years from this cell. Somehow a combination of the SUM, OFFSET, ROW & COLUMN formula.
You may use this formula:
=SUM(INDIRECT("R2C" & (MATCH(YEAR(TODAY()),$1:$1,0) - $C$3 + 1) & ":R2C" & MATCH(YEAR(TODAY()),$1:$1,0), FALSE))
But be aware I'm assume the current year - $C$3 is within your data range.
Brief explain:
YEAR(TODAY()) - it will return the year of current date, then you don't need to re-adjust every year
MATCH(lookup_value, lookup_array, match_type) - it will find the value matched in first row, and return the index of cell
INDIRECT() - Form the result of match to a R1C1 notation, and convert the text to excel range
A simpler formula could be to use the 4th parameter of OFFSET to set the width and to calculate the starting point of the OFFSET using YEAR(TODAY()0-2016
=SUM(OFFSET($B$2,0,YEAR(TODAY())-$C$1,1,$B$3))
NON VOLATILE OPTION
Well non volatile if it were not for the TODAY() function. Replace TODAY() with a cell containing the starting year as a date. or replace Year(Today()) with a cell reference just containing the year (integer) and then it will be a non volatile option.
=SUM(INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)):INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)-($C$3-1))
Volatile functions recalculate every time something on the spreadsheet changes.
Non volatile functions only recalculate when something affecting them changes.
The index function returns the cell address with in the range its looking. for a 2D range you need to give row and column reference. For a 1D range, you only need to give find the position within the range.
Match finds a value within a given range.
I have an Excel file in which some columns. The Excel is my bank account.
The D column is date, and not just for one day,its the days of a week.
I want to some all columns in that has the same date, and insert it in new cell.ex : for a week i should have 7 sum.
Here is some possible data from the sheet.
date(Column D) Money(Column K) Sum of same date(Column N)
1396/1/1 2300
1396/1/1 1000 3300 // some of the same date
1396/1/2 1200
1396/1/2 320 1550 // some of the same date
It is possible with Excel functions? Does I need a subroutin?
In L2 try,
=IF(ROW()=MATCH(D2, D:D), SUMIFS(K:K, D:D, D2), TEXT(,))
Fill down.
Use this formula:
=IF(D2<>D3,SUMIF(D:D,D2,K:K),"")
Then copy down
Hey you need to work with Sumif or SUMIFS and your Formula should like,
SUMIFS(D2:D10, C2:C10,">="&TODAY()-7, C2:C10,"<="&TODAY())
Or it should be like,
=SUMIFS(D2:D10, C2:C10,">="&A2, C2:C10,"<="&A3)
Or
=SUMIF(D2:D10, C2:C10,">="&TODAY())
NB: Sum Range is D2:D10 & C2:C10 is Criteria range.
In 2nd example A2 & A3 Cells holds Date value.
Suppose your Dates are in Col A & you want to Sum values in Column B, so instead of Sumif you can use this,
C2=SUMPRODUCT(--(MONTH(A$2:A$10)=ROW()-1),--(B$2:B$10))
NB: MONTH function will pull the Month value from A2 and add with corresponding Cell value in B, drag the formula below.
I have a list of sales data that includes the date of the sale and also a sales type code. I'm trying to use COUNTIFS to count how many sales of a specific type there were during each month .
So for example:
Date. Sales Type Code
10/01/2014. S
12/01/2014. S
15/01/2014. O
18/01/2014. S
02/02/2014. O
08/02/2014. S
Would give me the following results:
Code S
January - 3
February - 1
Code O
January - 1
February - 1
I have the formula
COUNTIFS('SALES LEDGER'!A:A,F2,'SALES LEDGER'!C:C,"<"&EOMONTH('MONTH Sales by Sales Type'!$C$1,0)+1)
Where A:A is the list of Sales Type Codes, F2 is the code I want to count, C:C is the list of dates and C1 is the first of the month I want to count (ie. 01/01/2014).
This works fine for January, giving me the expected result. But when I change C1 to 01/02/2014, it counts January and February together, rather than just February.
If anyone has any suggestions it would be appreciated!
Thanks
Your COUNTIFS formula specifies an end date but no start date, if you want to count for a specific month and year (based on C1) you need another criterion to specify the start date using C1, i.e.
=COUNTIFS('SALES LEDGER'!A:A,F2,'SALES LEDGER'!C:C,"<"&EOMONTH('MONTH Sales by Sales Type'!$C$1,0)+1,'SALES LEDGER'!C:C,">="&'MONTH Sales by Sales Type'!$C$1)
You could use this one (if your range with dates doesn't contain empty cells):
=SUMPRODUCT((MONTH(A2:A100)=1)*(B2:B100="S"))
or (if your range could contain empty cells)
=SUMPRODUCT((TEXT(A2:A100,"mmm")="Jan")*(B2:B100="S"))
If you need to add also year condition, just add *(YEAR(A2:A100)=2014) in any formula:
=SUMPRODUCT((TEXT(A2:A100,"mmm")="Jan")*(YEAR(A2:A100)=2014)*(B2:B100="S"))
Assuming:
it is amenable to use helper columns
Dates in col A
Sale Type Codes in col B
Results placed from A9:C11
Screenshot:
Add a helper col C to extract Month from date. Add this formula in C2 and drag down:
=TEXT(A2,"Mmm")
Add this formula in B10 and drag down and across:
=COUNTIFS($B$1:$B$7,B$9,$C$1:$C$7,$A10)
with the code below you can retrieve the month each date is in:
dim objDate as Date
dim i as integer
dim intMonth as integer
for i = 2 to 'number of row
objDate = CDate(cells(i, 1))
intMonth = Month(objDate)
next i
After figuring out the month with a simple loop you can count the number of sales in each month.