简体   繁体   中英

Count the number of time a string occurs per month

In my company we book serial numbers to each report and file we publish. These are booked by entering your name in one column (A) and then adding in the date it was taken in another column (B, formatted dd/mm/yyyy). Ie it looks as such below:

(A) (B) Initials Date A. Mustermann 16.03.2016 B. Mustermann 17.03.2016

There are a wide range of numbers depending on the types used, and a full break down is required monthly of who took out which type of serial numbers and how many of it. This I have grafted in to a table, on another sheet, and only really require a way to read the sheet and print the corresponding number. Like so;

        (A)       (B)      (C)
              Serial 1  Serial 2    etc…
A. Mustermann           
B. Mustermann 

Ideally this should avoid the use of Macros as many people use this file on differing software versions. I tried to use the CountIfs function and use the Month function to draw out the number for the month and match it with the number in set field, that way you only have to change that field to update the stats.

I tried to use: COUNTIFS('Sheet1'!A:A;A29;Month('Sheet1'!B4:B500);V2)

Where sheet1 is the initial serial log sheet, A29 is a sample string on the stats page that does occur in the A:A range and V2 is the month number, ie 3 for March. I want to know how many times A.Mustermann took out a Serial Type 1 in the month of March. That is the purpose of this task. The above function does recognise all inputs, ie the ranges and even is able to identify the Month of each date but for some reason it is unable to match the the two numbers together and get a final answer.

I appreciate all help.

Thanks

try the following sumproduct formula. It is basically counting the number of times something in column A occurs while at the same time there is a match in column B for a different criteria.

=SUMPRODUCT(--($A$2:$A$9=F2)*--(MONTH($B$2:$B$9)=G2))

The part of the formula that is the criteria check occurs inside the brackets after the --

 ($A$2:$A$9=F2)

We use the -- to convert the resulting true false result to a number 1 or 0.

The * does the job of the AND statement. So you can actually put multiple checks in as long as they are each separated by a * and the part within --() evaluates to either true or false. One last catch is the ranges have to be equal in length.

So in the above example A2:A9 was a range containing names, and B2:B9 was a range containing dates as in your first example data. F2 was the cell for the name I was checking for a match with, and cell G2 was the cell containing a number for a month to match to.

       (A)              (B)
(1)    Initials         Date
(2)    A. Mustermann    16/03/16
(3)    B. Mustermann    16/03/17
(4)    A. Mustermann    16/03/18
(5)    B. Mustermann    16/04/19
(6)    A. Mustermann    16/03/20
(7)    B. Mustermann    16/03/16
(8)    A. Mustermann    16/05/22
(9)    B. Mustermann    16/03/16

       (F)                 (G)
(1)    name                Month
(2)    A. Mustermann       3

The problem I am having is how serial 1 works into all based on your question. Right now the equation above will just count the number of times a name in column a with a match month beside its name. hopefully this will point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM