Excel Find Average Between Dates - excel

I have an unpivoted dataset where column A is country, column B are dates (01/01/2020 - 01/01/2021) and column C are number of Covid cases. In a separate tab I have a column A with the individual country names and I want to calculate the average of Covid cases for specific dates (e.g. between 01/01/2020 and 15/01/2020). However, using averageifs I keep getting #DIV/O!. Also, if I do "=IF(B2>1/1/2022,1,0)" where C2 is a date prior to 2021, I still get 1, which is wrong. I think something is wrong with the way dates are formatted but cannot seem to solve it. Any help would be really appreciated.
Thank you!

Related

Sum.if, without nesting 12 sum.if functions

I have a problem with an excel function, i "inherited" from a former colleague.
I have the two tables below:
My goal is to get the green field in Table 2 to show the sum of Person1s earnings from January to December. If months was =11 in Table 2, it should show the sum of Person1s earnings from January to November.
My current formular is a lot of nested "If" and "Sum.if" functions, but i wish to shorten it. Is it possible. I tried to say the sum area in the Sum.If to be all columns with data, but it still just returns the one from january (the first one it finds, i guess)
I hope someone can help me! Sorry for my bad english, but i'm not a native speaker
Best regards
Edit: Current formula by request
=IF(A2=0;0;IF($I$1=1;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L);IF($I$1=2;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M);IF($I$1=3;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N);IF($I$1=4;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O);IF($I$1=5;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P);IF($I$1=6;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q);IF($I$1=7;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R);IF($I$1=8;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S);IF($I$1=9;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T);IF($I$1=10;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U);IF($I$1=11;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U)+SUM.IF('Earnings'!A:A;A2;'Earnings'!V:V);IF($I$1=12;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U)+SUM.IF('Earnings'!A:A;A2;'Earnings'!V:V)+SUM.IF('Earnings'!A:A;A2;'Earnings'!W:W);"")))))))))))))
In B16, enter formula :
=SUM(OFFSET(B2,MATCH(A16,A3:A9,0),,,C12))
SUMIF is used to add the contents of a single column that match the criteria.
To achieve what you want, try this:
To shorten the formula significantly
=SUMPRODUCT(($A$3:$A$9=$A$14)*(B3:K9))
I have guessed your row and column numbers, but if you can't get it working just post your row and column headings and I will troubleshoot it.
Alternatively, if you would like to add another table with cumulative earnings, you could do it quite easily.
To provide cumulative earnings for each month for each person
For example, in B15 (or whatever the reference, we can't see your row/column number) you could have "Cumulative Jan", then fill right for a column for the cumulative earnings for each month. In that case B15 would say:
=SUM($B3:B3)
Then fill right and down.
This gives you cumulative earnings for any month for any person, in a table.
You could then do a lookup to that table if you wanted to, to return the matching value given the two inputs of person and month number.

Excel formula is giving me an answer in date format instead of a number

My data looks like this
Essentially I need to get the earliest buy date and subtract from all the sell dates for the same account number. To get the earliest buy date, I used the following formula:
=MINIFS(G:G,C:C,C53,E:E,"Buy")
G is the column where all the dates are, C is is where the account numbers are and column E is where the BUY and SELLs are located.
However when I do this formula
==SUMIFS(H:H,C:C,C48,E:E,"Buy")-H48
It is giving me a date number instead of the difference between two dates. Any ideas why?

Filtering or Importing data for specific date

I was wondering if anyone knows if it's possible to import a data, in a sort of a COUNTIF function but only for the data dated today?
I have 2 sheets, Attendance and Department.
In the Department tab, I have a list of employee's in column A. In column B and so on, I have a drop down option to select which department they're are stationed for each day. Each column represent a day, B being the 1st, C being 2nd, ... and so on. The header for each column has the day for the day as well.
On the attendance sheet, I have the list of Department in column A and in B, it is used to record how many employee are stationed at that department. I also have the day for the day on this sheet on A1.
Is it possible that when I change the date, the number of employee stationed in each department will change according to the date?
Is it possible to do this with just functions?
I've tried using the COUNTIF function, but I've found that I will have to change the range on a daily basis.
Use The Function: in B4 of Attendance Tab
=COUNTIF(INDIRECT("Department!" &ADDRESS(3,MATCH($A$1,Department!$A$2:$P$2,0)) & ":" &ADDRESS(6,MATCH($A$1,Department!$A$2:$P$2,0))),$A4)
Results: Attendance Tab
Department Tab:
I have used all the references as in the screenshots, you can change them if they are different in your sheet.
your question can be solved by SUMPRODUCT function. See below solution picture:
SOLUTION
Just to quickly explain my solution, I gave a name to the date on the Department sheet, called it 'Date_Lookup'; and I gave a name to the dates on the Attendance sheet, called it 'Date_List'. Names will simplify my formula especially when referencing across worksheets.
You will eventually find a lot of COUNIF scenario can be solved by SUMPRODUCT and this is just one example. SUMPRODUCT can do a lot IFs than COUNTIFS can do. In your case there are two criteria, one is which department did an employee attend to, and the other is on which date did the employee attend to that particular department. So my SUMPRODUCT formula can be understood as:
=SUMPRODUCT(('from the list of dates'='the particular date I want to see')*('from the full attendance record'='how many employees went to the given department'))
Let me know if you have difficulties understand my answer. A good 1 hour read through some online articles regarding SUMPRODUCT will help.
Cheers :)
Your first step would be to use a function to work out in which column the entered date appears. So in your Department sheet you enter a date in A1, then set B1 to:
=IFERROR(MATCH(A1, Attendance!2:2, 0), 0)
I use the IFERROR as I don't like seeing errors on my sheet. Assuming the result isn't zero, use a COUNTIF looking for the department letter in a range in the result column. I'd simply use on OFFSET to get the right range, but sticklers would tell you to find a different way of doing it. So long as your spreadsheet isn't going to increase in size to a massive complexity, OFFSET is fine.

How do I count how many occurrences per week something happens excel?

I am looking at a rather large excel spreadsheet with a long list of dates on it. Each one of these dates marks an error. What I am trying to find out is how many errors occur per week? From there I hope to make a control chart. Thanks so much and please let me know if there are any additional details I need to provide.
Just Like TMH8885 metioned get week number from each date and then assuming that your dates are in Column A and weeknumbers are in column B make a table that list numbers from 1 to 52 next to which enter a COUNTIF(B:B,D2)(change D2 to cell pointing at correct week number of course).
In the screen shot I was lazy and included only 22 weeks for my table.
You could use the WEEKNUM function to pull which week of the year the error occurred in.
=WEEKNUM(your date cell)
From there you could use a pivot table to pull in the weeks then find the average count of errors.

Excel SUMIF between dates

I have column A with date values formatted as mm/dd/yyyy. I am trying to sum the values of column B if A >=DATE(2012,1,1) AND
=SUM(B:B) sums B properly, but if I try to use =SUMIF(B:B,A:A>=DATE(2012,1,1)) the value returned is 0.00. I'm assuming this has something to do with using decimal for the sum and date type for the criteria. Is there a way to get around this?
Thanks
You haven't got your SUMIF in the correct order - it needs to be range, criteria, sum range. Try:
=SUMIF(A:A,">="&DATE(2012,1,1),B:B)
To SUMIFS between dates, use the following:
=SUMIFS(B:B,A:A,">="&DATE(2012,1,1),A:A,"<"&DATE(2012,6,1))
I found another way to work around this issue that I thought I would share.
In my case I had a years worth of daily columns (i.e. Jan-1, Jan-2... Dec-31), and I had to extract totals for each month. I went about it this way: Sum the entire year, Subtract out the totals for the dates prior and the dates after. It looks like this for February's totals:
=SUM($P3:$NP3)-(SUMIF($P$2:$NP$2, ">2/28/2014",$P3:$NP3)+SUMIF($P$2:$NP$2, "<2/1/2014",$P3:$NP3))
Where $P$2:$NP$2 contained my date values and $P3:$NP3 was the first row of data I am totaling.
So SUM($P3:$NP3) is my entire year's total and I subtract (the sum of two sumifs):
SUMIF($P$2:$NP$2, ">2/28/2014",$P3:$NP3), which totals all the months after February and
SUMIF($P$2:$NP$2, "<2/1/2014",$P3:$NP3), which totals all the months before February.
this works, and can be adapted for weeks or anyother frequency i.e. weekly, quarterly etc...
=SUMIFS(B12:B11652,A12:A11652,">="&DATE(YEAR(C12),MONTH(C12),1),A12:A11652,"<"&DATE(YEAR(C12),MONTH(C12)+1,1))
One more solution when you want to use data from any sell ( in the key C3)
=SUMIF(Sheet6!M:M;CONCATENATE("<";TEXT(C3;"dd.mm.yyyy"));Sheet6!L:L)

Resources