I am trying to write a formula that counts all of the entries on a table that are on a specific weekday AND within a certain time range. Below is a sample table:
How would I write a formula to count all entries that occurred on a Monday between the times of 02:00-20:00?
I can get it to count entries within the time range with a simple COUNTIFS using >= and <= within the range using =COUNTIFS(Table1[Time], ">=02:01",Table1[Time],"<=19:59"), but am struggling adding the third conditional statement of weekday. I have tried playing around with the WEEKDAY function without success.
You can use:
=SUMPRODUCT((WEEKDAY(Table1[Date])=2)*(Table1[Time]>TIME(2,0,0))*(Table1[Time]<TIME(20,0,0)))
You may also try-
=SUM((TEXT(Table1[Date],"dddd")="Monday")*(Table1[Time]>=TIME(2,0,0))*(Table1[Time]<=TIME(19,59,0)))
May need CSE entry for older version of excel. CSE means enter formula by pressing CTRL+SHIFT+ENTER.
Related
I'm trying to count the number of distinct text from a specific date in a data table.
Data Sample with expect result :
I was able to figure out how to count the distinct element from a range I specify, because I can determine the first and last row containing the date.
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
I have tried to modify my formula so that it determines the cell range by itself but without success.
I searched for an answer, using a combination of CELL and MAXIFS, example below, but Excel does not accept the formula.
=CELL("row",MAXIFS(A2:A15,A2:a15,D2))
I've looked at the INDEX formula, but I can't figure out how to do what I want to do. 😑
Any idea what I'm doing wrong, or what I should be doing instead?
Thanks, I appreciate it!
If you have Office 365 and the new Dynamic Arrays, this sort of formula has become ridiculously easy.
This formula in cell E3:
=COUNTA(UNIQUE(FILTER($B$2:$B$15,$A$2:$A$15=D3)))
Copy down.
You can also generate the unique list of dates with this formula in D3, which spills down automatically and does not need to be copied.
=UNIQUE(A2:A15)
It wasn't easy, but by separating each step of the problem, I was able to solve it.
Note that my solution only works because my dates are sorted.
Here's the final formula in the cell "One formula to rule them all":
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2))),INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)))))
Here are my explanations of my process:
Formula if I select the range :
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
Formula to get the first iteration
=ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2)
Formula to get the last iteration
{=ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)}
Create range from two addresses
=INDIRECT(CONCATENATE(F3,":",G3))
Formula giving me the expect result
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(F3,":",G3)),INDIRECT(CONCATENATE(F3,":",G3))))
I have a price column and a date column. The date column includes 2019 and 2018.
I'm trying to get the median price value for each year.
Tried Median with If as an array specifically using the date and less than or greater than to identify if the proper year is selected.
You can use the Median() function with a nested IF.
=MEDIAN(IF(YEAR($B$2:$B$6)=D$1,$A$2:$A$6))
If you already have a version of Excel that supports Dynamic Arrays, you can just enter the formula. If you have a version without Dynamic Arrays, you need to use Ctrl+Shift+Enter to confirm the formula.
you can use the array formula - it will be a little simpler
{=MEDIAN(IF(E1=YEAR($B$2:$B$5);$A$2:$A$5;""))}
Array formula after editing is confirmed by pressing ctrl + shift + enter
Addition:
No, AND function can't work with arrays. In case with additional conditions use following array formula:
{=MEDIAN(IF(E1=YEAR($B$2:$B$5)*($C$2:$C$5="x");$A$2:$A$5;""))}
And empty cells are not included in the MEDIAN calculation because previous conditions.
I have a time tracker and trying to count time spent in a given week using SUMIFS.
The week column is a formula that gets the week number from the date, and not a value by itself, and that seems to be tripping up the SUMIFS calculation, and it just returns SUM of zero. If I replace the formula with a written week number, it works.
Is there a way to force SUMIFS to work with the formula, or make it see the value of the cell instead of the formula?
A B C D
wk48 johnny 29-11-18 misc 10
wk48 johnny 29-11-18 inbound 130
wk48 johnny 29-11-18 meeting 30
Column A is =WEEKNUM(C,2).
My SUMIFS formula is =SUMIFS(D:D,A:A,"wk48"), but like I said, it only returns zero. If I change the data in column A to be just text instead of getting the week number by formula, it works just fine.
(I'm using SUMIFS instead of just SUMIF because I want to add other criteria as well, but for now I'm trying to get the individual criteria working before combining them together, and I'm stuck on this one.)
Any ideas? Thanks.
the WEEKNUM formula returns numbers, 48 in your case, and not the string "wk48". I suspect this is how the cell is formatted (the same way you can have a dollar sign in front of a number). Try =SUMIFS(D:D,A:A,48).
I have collision data in column F I have the years from 2004-2015, I have named the range ATT_YEAR and In column G I have the dates and the range is named ATT_DATE. What I am trying to do is to either use COUNTIFS or SUMPRODUCT to determine the number of collisions by month of the year, if I select the year as say 2013, I want to show the number of collisions by month.
I was trying the following the formula:
=COUNTIFS(ATT_YEAR,"2013",ATT_DATE,MONTH=1)
but not getting very far with one.
Or when I tried using sumproduct formula:
=SUMPRODUCT(--(ATT_YEAR,"2013"),MONTH(ATT_DATE)=1)
I would be grateful for any assist on either of these.
I think you are using the formula wrong:
=SUMIFS(COLLISION,ATT_YEAR,2013,ATT_MONTH,1)
This will count all collisions in the named-range "COLLISION" only if 2013 is matched in the named-range "ATT_YEAR" and 1 (i.e. January) is matched in the named-range "ATT_MONTH".
edit
Needs updating, wrong assumptions.
You cannot use MONTH, which is the function you need, inside COUNTIFS. Instead, create another column, with the formula MONTH(B2), assuming column B has the date values, and use it as a new ATT_MONTH range:
=COUNTIFS(ATT_YEAR,2004,ATT_MONTH,6)
I have to put together a weekly reporting system in Excel. I need to report on the month to dale sales results and the completed week (Fri-Thu). This is collected from multiple sales agents in sales documents stored in Sharepoint.
For this, I've used "SUMIFS" to collect the data, the following way:
=SUMIFS('SHAREPOINTREF/FILE.xlsm'!SalesResults[One off],'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],">="&B7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],"<="&C7)
(B7 is a cell reference which determines the start date of the week, with C7 being the end of the week)
The trouble with SUMIFS, as well as SUMIF, COUNTBLANK, COUNTIF and COUNTIFS, is that they don't work when the sourcing document is closed. Microsoft has a workaround here: https://support.microsoft.com/kb/260415?wa=wsignin1.0
I can't seem to figure out how to adapt the workaround methodology recommended to apply not just to a simple IF statement, but to multiples. I assume I would need to use an "AND" statement, but I keep getting errors when I'm trying.
I have about half a dozen different calculations to make, but I am pretty confident if I can solve this one, the others should start to gel a bit better.
Try this:
=SUM(IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7,IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])))
Entered using Ctrl+Shift+Enter.
Non-Array formula equivalent:
=SUMPRODUCT(--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7),--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7),'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])
But both seems to return #REF! when source WB is closed even though the link provided in the question claims otherwise.
Edit1:
After more digging, above will work but you need to use a Normal Range and not a Table Range.
The only problem is, you loose the advantage of Table's Dynamic Data Range.
So something like this will work even if the source is closed:
=SUMPRODUCT(--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11>=B7),--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11<=C7),'SHAREPOINTREF/[FILE.xlsm]Sheet1'!$B$2:$B$11)
The recommended solution is to use array formulas. Those are a special type of formula that, when typed, must be activated by pressing Ctrl + Shift + Enter in the formula bar. Such a function works by applying a function that would normally accept a single cell (such as IF() ) to a range. You will need to wrap the result in an aggregating formula such as SUM() or COUNT(). Here's an example:
=SUM(IF($A$1:$A$10="Apple", $B$1:$B$10, 0))
This formula would check each cell from A1 to A10 and compare it to "Apple", if it is true it will return the corresponding row from $B$1:$B$10. The result would be an array of values of column B where column A is "Apples" with zeros where it is not. The surrounding SUM() aggregates the array and gives the equivalent of SUMIF().
As I mentioned, you would need to enter Ctrl + Shift + Enter after typing the formula for it to work as an array formula. Otherwise, it will work as a regular formula.