Countifs to match OR conditions? - excel

I have the following countifs formula
=COUNTIFS($F$2:$F$848,Summary!$F5,'Report'!$G$2:$G$848,$Q$10,$G$2:$G$848,$Q$11)
on my sheet, Q10 = Monday, Q11 = Tuesday
On 'Report', G2:G848 contains login data
Objective: I need the total count from Report that are either on Monday(Q10) or Tuesday (Q11)
With the current formula I have, countifs is looking for rows that has Monday and Tuesday in the row, which is a wrong.
How can I solve this ?

Presumably F2:F848 is also on Report sheet? Try this
=SUMPRODUCT(COUNTIFS('Report'!$F$2:$F$848,Summary!$F5,'Report'!$G$2:$G$848,$Q$10:$Q$11))
Assumes formula resides on same sheet as the Q10 and Q11 values....
The COUNTIFS function will return an "array" of 2 values, one for Monday (Q10) and one for Tuesday(Q11), then SUMPRODUCT just sums the 2 values to give you the total for both days

=COUNTIF('Report'!$G$2:$G$848,"Q10")+COUNTIF('Report'!$G$2:$G$848,"Q11")
This assumes that 'Report'!$G$2:$G$848 contains the Q10 and Q11 values you're talking about.

Related

Only calculate when finished entering week

I needed help generating a formula week wise. My goal is to have the First Contact (FC) and Follow-up (FU) calculated from Wednesday of a week to the Tuesday of next week by looking at the dates. So, in this case on cell M10 the FC should be 5 and on cell N10 the FU should be 3 and then again it would calculate for the next week from Wednesday until Tuesday so on M16 it should calculate FC as 1 and on N16 the FU as 4.
I need to continuously record data for further weeks therefore need a formula which could do so. Would a SUMIF be a good option here?
Currently I have the following formulas:
=COUNTIF(A:A,"First Contact") which calculates 6
=COUNTIF(A:A,"Follow-up") which calculates 7
Formula in cell C2:
=IF(A2<>"";"";COUNTIFS(A:A;"First Contact";B:B;"<="&B1;B:B;">="&B1-6))
Formula in D2:
=IF(A2<>"";"";COUNTIFS(A:A;"Follow_up";B:B;"<="&B1;B:B;">="&B1-6))
Drag to bottom.
Since your data is sorted you could use the following:
In M10 use: =COUNTIF($A$1:$A10,"First Contact")-SUM(M$1:M9)
And in N10 use: =COUNTIF($A$1:$A10,"Follow-up")-SUM(N$1:N9)
And since your results show in an empty row, if you want a draggable solution, wrap it in IF like this: =IF($A10="",COUNTIF($A$1:$A10,"FC")-SUM(M$1:M9),"")
The $ in the range reference for column letter and row number will lock the position if you drag the formula or copy it and paste it elsewhere.

How to nest multiple if functions to result in different vlookups in Excel?

I am trying to auto populate start dates for a specified time frame based on 2 sets of criteria. Criteria 1 is the name of the time frame, in my example "Period 1, Period 2". Each Period can have different starting days which would be criteria 2 "Monday, Tuesday". I have tables set up with specified dates that correlate to the starting day of the week. this table is named "_effectivedates".
Essentially what I am wanting to achieve would be:
If B11 = Monday then look up starting date that matches "Period 1" in B17 from _effectivedates column 2. IF B11 = Tuesday then then look up starting date that matches "Period 1" in B17 from _effectivedates column 4.
Below is the formula I have tried, it seems to work fine with one if B11 = Monday, but if i change B11 to read Tuesday it returns "false"
=IF(B11="Monday",VLOOKUP(B17,_effectivedates,2,IF(B11="Tuesday",VLOOKUP(B17,_effectivedates,4,))))
It's returning "False" when Tuesday because you didn't close your parenthesis after you first vlookup. The formula should be:
=IF(B11="Monday",VLOOKUP(B17,_effectivedates,2),IF(B11="Tuesday",VLOOKUP(B17,_effectivedates,4)))
What you could do is a translation table of Monday = 2 and Tuesday = 4 and so on and use vlookups to know what value to use.
Somewhere in the workbook:
A B
Monday 2
Tuesday 4
And so on...
Then your vlookup will be:
=Vlookup(B17,_effectivedates,Vlookup(B11,[range above],2, false), false)
So you vlookup the weekday and use that in the vlookup.

Counting unique values in a column that matches multiple criteria in a single column

I'm trying to count how many values in column A multiple multiple criteria that are mixed in column B. I was able to do this using a helper column (column C). To better get the idea, please see below:
Row Column A Column B Column C
Day Shift Helper
1 Monday Worked AM Worked PM
2 Tuesday Worked AM
3 Wednesday Worked AM Worked PM
4 Monday Worked PM
5 Wednesday Worked PM
Column A contains days from Monday to Wednesday, column B contains shifts while column C contains a formula to return "Worked PM" if that day also has a "Worked PM" somewhere below. Basically, Monday and Wednesday has these in rows 4 and 5.
Formula for cell C1 is =IF(B1="Worked PM","",IF(COUNTIFS($A$1:$A$5,$A1,$B$1:$B$5,"Worked PM")>0,"Worked PM",""))
The reason why I have this helper column is because I want to count the days that have both "Worked AM" and "Worked PM" on them. In our example, the count formula should return 2. I used the following formula, which is working perfectly: =COUNTIFS($B$1:$B$5,"Worked AM",$C$1:$C$5,"Worked PM")
However, I wish to completely eliminate the helper column (column C), which I have failed to do ever since. I tried making use of SUMPRODUCT, COUNT+MATCH and COUNTIFS. I've seen tutorials on how to do this from different Excel help sites, but I've seen nothing that matched my concern. They were "close" (not sure), but when I reconfigure them, I always fail.
I've turned to here as my last stop before giving up. I want to ask if what I'm actually doing is impossible. If it is possible, I would as well seek your guidance on how can I arrive on the solution. Thanks in advance! :)
This will replicate the results from your helper column method. Enter as an array formula (ctrl+shift+enter):
=SUM(--IF(B2:B6="Worked AM",IFERROR(MATCH(A2:A6,IF(B2:B6="Worked PM",A2:A6),0),0)>0))
But unless you have duplicate row entries, wouldn't the count simply equal the number of repeats you have in column A? You don't have to enter this as an array formula:
=SUM(--(FREQUENCY(MATCH(A2:A6,A2:A6),ROW(A2:A6)-ROW(A2)+1)>1))

SumIf by Weekday & User

I have a table that I am trying to perform a sumif on, but the catch is I need the formula to filter the data by two range criteria first.
Column A = Date, Column D = User, Column H = time to be summed
Basically, I want to be able to sum the time values by user, but then I also need to be able to split this time between weekdays and weekends.
Thus, if user A has 1 session of 0:30 on Monday, Wednesday, Saturday and Sunday, then I want the formula to be capable of summing the 2 hrs such that I can have 1 column in a separate table with the weekday hours, and the column next to this with the summ of all weekend hours.
Any ideas you might have on how I can solve this with a formula rather than redesigning the tables (as they're not mine to redesign) would be most appreciated.
You need to move to a SUMPRODUCT function in order that you can introduce the WEEKDAY function to be used in the criteria.
    
The formula in K2:L2 are,
=SUMPRODUCT(($D$2:$D$99=$J2)*(WEEKDAY($A$2:$A$99, 2)<6), $H$2:$H$99)
=SUMPRODUCT(($D$2:$D$99=$J2)*(WEEKDAY($A$2:$A$99, 2)>=6), $H$2:$H$99)
Fill down as necessary.

COUNTIFS with range criteria on different sheets

I have not read if there is a limitation with COUNTIFS function, but I am experiencing the following:
I want to count the number the number of times two conditions are true in a row. For example
Sheet 1
USERID DATE
SAM 12/1/2014
SAM 12/3/2014
SAM 12/4/2014
JON 12/3/2014
BOB 11/5/2014
Sheet 2
Dates to match against {12/3/2014, 12/4/2014, 12/5/2014}
Sheet 3
USERID DATECount
SAM 2
JON 1
BOB 0
If all this information is in the same sheet the following formula works (Assuming data in Sheet 1 is in columns A and B, and the data in Sheet 2 is in the first row D to F, and the data in Sheet 3 starts at D5.
=COUNTIFS(A:A,D5,B:B,"="&$D$1:$F$1)
Currently, to get over this, I have a SUM function and a COUNTIFS for each criteria in the range for criteria 2. But it's pretty ugly since there are 20 criteria.
What I trying to find is a more elegant way to do this, or if there is another function that can return the same results.
Note that the date range can change every month.
You need a SUMPRODUCT wrapper that will iterate the COUNTIFS results through the cells in Sheet2!$D$1:$F$1.
      
The formula in Sheet3!E5 is,
=SUMPRODUCT(COUNTIFS(Sheet1!A:A,D5,Sheet1!B:B,Sheet2!$D$1:$F$1))
Fill down as necessary.

Resources