Countif only one per row

janarthenan

New Member
Joined
Jun 11, 2016
Messages
22
Hi All

I have been trying to achieve the following for days now and can't seem to figure out a way.

I have a spreadsheet with dates when a supervision is done for a particular staff.

I am trying to have a weekly report so that I know on that particular week what my supervision Percentage was.

Every staff needs their supervision done at least every 3 months.

When I do the COUNTIF and if some one had their supervision twice (one in April and one in June) on the June calculation it counts it as 2.

[TABLE="width: 1000"]
<tbody>[TR]
[TD]Name[/TD]
[TD]April[/TD]
[TD]May[/TD]
[TD]June[/TD]
[TD]July[/TD]
[TD]August[/TD]
[TD]Sept[/TD]
[TD]Oct[/TD]
[TD]Nov[/TD]
[TD]Dec[/TD]
[TD]Last Supervision[/TD]
[TD]Next Supervision[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]1/4/17[/TD]
[TD][/TD]
[TD]1/6/17[/TD]
[TD]1/7/17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]=MAX(B2:J2)[/TD]
[TD]=H2+90[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD][/TD]
[TD]1/5/17[/TD]
[TD][/TD]
[TD][/TD]
[TD]1/8/17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]=MAX(B3:J3)[/TD]
[TD]=H3+90[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]..[/TD]
[TD]..[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]F[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

When I do COUNTIF(B2:J2, "<="&1/4/17) - I get 1
When I do COUNTIF(B2:J2, "<="&1/7/17) - I get 3 (Which is correct) but I want this to be one.
- So basically I want the calculation to count the highest value only per row and If that highest value meets the COUNTIF condition to come back as 1.

Prefer if no VBA was used.

Regards
J
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I'm not at all clear on what you want but if the following is true ..
When I do COUNTIF(B2:J2, "<="&1/7/17) - I get 3 (Which is correct) but I want this to be one.
.. then does this do what you want?
MIN(1, COUNTIF(B2:J2, "<="&1/7/17))
 
Last edited:
Upvote 0
Hi Peter
Thanks for your quick reply.

I am sorry, its a little difficult to explain as I am unable to attach a file.

I might have not explained myself clearly there.
My Formula is actually (B2:F3) It covers a range rather than a single row.
So When I Do When I do COUNTIF(B2:F2, "<="&1/7/17) - The answer I get is 4. But i want it to be 2.
So it should if a row contains two values then only the highest value should be counted.
On a row by row basis this is achievable but when the whole range is selected it seems impossible.

Jan
 
Upvote 0
You cannot attach files but you can post small screen shots that can be copied (see my signature block below for a link), or even a table like you did above (but tell us what the rows and columns are).

Instead of telling us what formula you are trying to use, show us the results that you want (manually entered) on that screen shot and then explain in words how you manually come up with the results. Then we will see if we can devise a formula to do it.

It might also clarify better if you give us a few more than 2 rows of data. Say 5 or 6.
 
Upvote 0

Book1
ABCDEFGHIJKLMNOP
2SuperviseeLast Supervision from Prev.Apr - 17May - 17Jun - 17Jul - 17Aug - 17Sep - 17Oct - 17Nov - 17Dec - 17Jan - 18Feb - 18Mar - 18Last Supervision DateNext Supervision
3A22/11/201605/05/201705/05/201703/08/2017
4B21/02/201701/04/201702/06/201702/06/201731/08/2017
5C14/11/201610/05/201719/07/201719/07/201717/10/2017
6D09/03/201721/05/201721/05/201719/08/2017
7E17/02/201711/04/201704/06/201704/06/201702/09/2017
8F10/07/201702/05/201710/07/201708/10/2017
9G21/01/201701/04/201710/06/201703/08/201703/08/201701/11/2017
10H10/09/201623/05/201723/05/201721/08/2017
Supervision (2)


This is the Raw Data Table:

The Below is the Calculation Table:

Book1
DEFG
13Week EndingSupervisionValue Should beHow (Value Should Be is Calculated)
1408/04/20176.003.00The formula should count all dates in the range (B3:N10) that fall between Week Ending (Column D) and Week Ending - 90 Days. If there are 2 values in a row then it should only count the highest value. For Example - Supervisee B has 2 Dates (21/02/17 and 01/04/17) but the lowest date should be ignored and should be counted as 1.
1522/04/20176.004.00
1606/05/20178.005.00
1720/05/20178.006.00
1803/06/201710.008.00
1917/06/201711.008.00
2001/07/20179.008.00
2115/07/20179.008.00
Supervision (2)


Thanks for all the Help

Jan
 
Upvote 0
Sorry, I still don't understand. (But thanks for the images where we can see what rows and columns the data is in)

For one thing, you said "For Example - Supervisee B has 2 Dates (21/02/17 and 01/04/17)", but when I look at Supervisee B I see 3 dates, the 2 you mentioned but also 02/06/2017. Please clarify.

Could explain exactly how you came up with a count of 3 for cell F14 in the 2nd image, including which cells from the top image were counted and why?
 
Last edited:
Upvote 0
Hi Peter

Let me explain the Row 14.
The week ending date is 08/04/17.
My criteria should count any dates between 08/01/17 (90 dates before the week ending date) to 08/04/17.
So the value counted 6.

But In the example of Supervisee B there are 2 dates that fall in this criteria. (21/02/17 and 01/04/17)
But I only need the biggest date to be counted i.e. 01/04/17.

In Summary if there are two dates in a row that satisfy the criteria (i.e week ending date to week ending date-90) then the highest date should be counted and the rest ignored.

Thanks
Jan
 
Upvote 0
Let me explain the Row 14.
The week ending date is 08/04/17.
My criteria should count any dates between 08/01/17 (90 dates before the week ending date) to 08/04/17.
So the value counted 6.
Ok, I can see the count of 6 (coloured cells below) but earlier you said ...
If there are 2 values in a row then it should only count the highest value.
.. so to me that should eliminate the 2 blue cells leaving a count of 4 (green). How do you arrive at the expected value of 3 as shown in post 5? :huh: :confused:


Excel 2016 (Windows) 32 bit
ABCDEFG
2SuperviseeLast Supervision from Prev.Apr-17May-17Jun-17Jul-17Aug-17
3A22/11/20165/05/2017
4B21/02/20171/04/20172/06/2017
5C14/11/201610/05/201719/07/2017
6D9/03/201721/05/2017
7E17/02/201711/04/20174/06/2017
8F10/07/20172/05/2017
9G21/01/20171/04/201710/06/20173/08/2017
10H10/09/201623/05/2017
Count
 
Upvote 0
Peter

Apologies, You are right, it should be 4, I missed out one of the dates.

Thats exactly what I am trying to achieve.

Jan
 
Upvote 0
I know you said you would prefer without vba but so far I have not been able to come up with a formula to do the job. There likely is one and perhaps somebody else will be able to post that for you.
Until then, you might consider the vba approach via a user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Note: You referred to checking back 90 days. My function should do that, but if you actually wanted to check back 3 months instead, use the other 'EarlierDate' line in the code that is currently commented out.

Rich (BB code):
Function Count_Rows(RngToLookIn As Range, DateToCheck As Date) As Long
  Dim aRangeToLookIn As Variant
  Dim EarlierDate As Date
  Dim i As Long, j As Long
  
  aRangeToLookIn = RngToLookIn.Value
  EarlierDate = DateAdd("d", -90, DateToCheck)
  'EarlierDate = DateAdd("m", -3, DateToCheck)
  For i = 1 To UBound(aRangeToLookIn, 1)
    For j = 1 To UBound(aRangeToLookIn, 2)
      If aRangeToLookIn(i, j) <= DateToCheck Then
        If aRangeToLookIn(i, j) >= EarlierDate Then
          Count_Rows = Count_Rows + 1
          Exit For
        End If
      End If
    Next j
  Next i
End Function



Book1
BCDEFGHIJKLMN
2Last Supervision from Prev.Apr-17May-17Jun-17Jul-17Aug-17Sep-17Oct-17Nov-17Dec-17Jan-18Feb-18Mar-18
322/11/20165/05/2017
421/02/20171/04/20172/06/2017
514/11/201610/05/201719/07/2017
69/03/201721/05/2017
717/02/201711/04/20174/06/2017
810/07/20172/05/2017
921/01/20171/04/201710/06/20173/08/2017
1010/09/201623/05/2017
11
12
13Week EndingSupervisionCount
148/04/201764
1522/04/201764
166/05/201786
1720/05/201787
183/06/2017108
1917/06/2017118
201/07/201798
Supervision
Cell Formulas
RangeFormula
F14=Count_Rows(B$3:N$10,D14)
 
Upvote 0

Forum statistics

Threads
1,223,761
Messages
6,174,342
Members
452,555
Latest member
colc007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top