+ Reply to Thread
Results 1 to 17 of 17

Conditional occurrences count

  1. #1
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Post Conditional occurrences count

    Hello,

    I have attached an extract of the movements in my warehouse for one article, so the needed formula must be applied to all the articles (long_code).The idea is to write the correct formula in column "test".
    The idea is to see an article how many times is sold in a period (in this example since 20/12/2021 until today). So I need to take in consideration only the outgoing invoices that will raise the occurences while the credit note will lower by one. In the entire period have been sold 98 pieces. And there were 15 succesful sales. My formula shows 17, because sometimes happens that the same article is present on more rows in the same invoice (3000000600 & 0000010702). I have no idea how to modify the formula, any idea?

    The other thing is to put also another condition in the formula, for example I would like to count only the occurences for the company E or esclude the company E from counting.

    Could you help, please?
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Conditional occurrences count

    Would you manually add the results you expect please. It's always easier to answer if we know the final destination.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Hello,

    I have already written it, it is 15 (the succesful sales).

  4. #4
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Any ideas? Is not a mandatory to use the countif formula.

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    This proposal adds a helper column (K) to the table.
    The formula for the helper column is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The formula for the Test column is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that the beginning date is placed in cell O1 instead of being hard coded into the formula so that it can be easily changed.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  6. #6
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Hello,

    thank you very much for the given answer. I have a question : why in the formula you put "-2*COUNTIFS...."? Does in this way toggle two times a credit note? In the first part of the formula you count the credit note once, so I suppose that you need to toggle it only once.

    Please let me know.

    Thank you.

    Have a nice day.

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    The following formula counts the invoices once and the credits once while still yielding an answer of 15:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that you may need to use semicolons instead of commas based on whether one and one-tenth is written 1,1 instead of 1.1
    Let us know if you have any questions.
    Last edited by JeteMc; 07-25-2022 at 10:23 AM.

  8. #8
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Cool Re: Conditional occurrences count

    Hello again,

    it this way the formula is cleaner for me. Thank you.

    Anyway it does not work in the correct way for all the cases that I have. On the second sheet, I put another example for another product.

    The final result should be 1 and not 0.

    The last two rows are excluded from the count due to the dates < "19/12/2021".

    The fifht and sixth rows is the same invoice (10650), the part number is present twice, so the helper column do the right thing, I think, the total sold quantity is 2.
    In the fourt row, we have a credit for one and the same in the second row. These 2 cancels the 2 of the invoice 10650.
    So we have only one real sale of 2 quantities with the invoice 10728.

    Any ideas how to change the formula?

    I have also another question : if I would like to exclude from the count a company or more companies (A,B,C), what should I do in the count formula?
    Attached Files Attached Files
    Last edited by Ronyn; 07-28-2022 at 11:09 AM.

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    As to ideas to change the formula in the Test2 column, try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that the date Dec 19, 2021 is placed in cell O1 as my system reads 19/12/2021 as being the 12th day of the 19th month of 2021 which doesn't exist.
    As to excluding companies, please provide a sample that illustrates the request. Remember to tell us the expected result.
    Let us know if you have any questions.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    The provided formula is not ok. On the first sheet, it should count 15 as well as the column "TEST" in order to be ok. In the column "Test2" it shows 85.
    I am not looking for a formula that it would be ok for one case as it happens in the second sheet. The general idea is to count for any sold article within a period, how many times it has been sold. You can have an invoice for one piece or one for 10 pieces. It has to be counted once. From the count they are excluded the credit notes, because it is a return of a sale. So if I sold 10 with an invoice, you have to have a credit note for 10, to cancel it from the count. Of course the customer has to be the same. If happened like in the second sheet in which we have one invoice (10650) with two rows because the quantity sold is 2*-1, and afterwards we have two separate credit notes (10726 and 10820) with quantity +1, the final results is the same : 2*-1 -2*+1 = 0. It could happens also that a customer buys two pieces and return back only one, so you could have one invoice with -2 pieces and one credit note with +1 piece. So it should be counted as a complete sale (a +1 increment to the occurrences).

    Regarding the excluding companies : to the existing formula we have to add an additional rule. Following what we already have on the first sheet as data, we have 15 occurrences. If I want to exclude the company "C", the occurrences will become 13. If I want to exclude "C" & "E", the occurrences will become 9. If I want to exclude only "B" (the customer with the credit note), the total occurrences will become again 15.

    I hope that now it is more clear.
    Last edited by Ronyn; 07-29-2022 at 06:26 AM.

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    As to the excluded companies on the Лист1 sheet try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that P2:P4 may be used to name companies to be excluded from calculation.
    I am confused as to why the Test2 column on Sheet1 should show 1 given the explanation in post #10.
    I have put my understanding of how each row affects the count in column M and the running count in column N. Perhaps you could tell us where my understanding in incorrect so that we can attempt to write a formula that will work on both sheets.
    Let us know if you have any questions.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Hello,

    Probably I wasn't enough clear. I will try to explain in another way. Anyway, thank you for the exclusion company formula. It is clear.
    I will start on the second sheet. We have invoice 10650 invoiced to company A, two rows with 1 sold piece. It is correctly counted once. But on this invoice we sold
    -1-1=-2 pieces of 0634.349.853:000 to company A. Afterwards we have two credits 10726 & 10820 for +1 piece of 0634.349.853:000 to company A. The total amount of pieces that return back on stock are 1+1=2 that cancel the previous -2 sold pieces. So in this case one invoice is cancelled by two credit notes. We have to take in consideration also the sold quantities and the returned ones, not only the count of the invoices or the credit notes. With invoice 10728 we sold -2 pieces to company B, so this make the sales count +1 with a total amount of sold pieces -2.

    Just to be sure that you will understand me. If on invoice 10650 the total sold quantity to company A was -3, afterwards with the two credit notes which the total returned quantity is +2, -1 quantity will remain sold to company A, so that means a +1 sales count that summed with the other one of company B, it will become +2. The total sold pieces will be -3 (-2 to company B and -1 to company A).
    Last edited by Ronyn; 07-31-2022 at 06:25 AM.

  13. #13
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    I have reached out to the other contributors to see if one of them may be able to help.

  14. #14
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Hello,

    thank you very much for your support for everything. I never used the sumproduct function, it is new thing for me, and it opens a lot of new possibilities.
    Anyway I have a question, I used the formula :
    =SUMPRODUCT(([long_code]=[@[long_code]])*([document_date]>N$2)*([document_type]="invoice")*([Helper]=1)*([company_name]<>P$2)*([company_name]<>P$3)*([company_name]<>P$4))-SUMPRODUCT(([long_code]=[@[long_code]])*([document_date]>N$2)*([document_type]="credit")*([Helper]=1)*([company_name]<>P$2)*([company_name]<>P$3)*([company_name]<>P$4))

    but instead of putting the date referenced to a cell like N$2, I put directly the value 19/12/2021 or "19/12/2021", but it does not work. I tried different combination until I found that it works if I put Datevalue("19/12/2021")

    Is this the only way? Why I should use Datevalue?

  15. #15
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Conditional occurrences count

    "19/12/2022" is a text string and all of the values in the document_date column are numbers (days since 1/1/1900).
    DATEVALUE converts the text string into a number so that it can be compared to the values in the document_date column.
    You could also use the DATE function and manually fill in the year, month and day values.
    I hope that makes sense.

  16. #16
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53
    Quote Originally Posted by JeteMc View Post
    all of the values in the document_date column are numbers (days since 1/1/1900).
    For the other thing i am agree with you, is 19/12/2021 not a number? Why if i put the condition > 19/12/2021, it does not work?

  17. #17
    Registered User
    Join Date
    02-03-2021
    Location
    Bulgaria
    MS-Off Ver
    Home and Business 2019
    Posts
    53

    Re: Conditional occurrences count

    Hello,

    I have a similar case as this one as in the past. It is a little bit different, and I need help.report.xlsx
    The attached table has date column, an offer number column, a column with the company name, a column Invoiced which means if an offer became an invoice. I add 3 additional columns.
    Total offers calculates all the offers made to each company while hit rate shows how many offers became invoices.
    I need help for the column offers. Here a I want to calculate the following :

    a sum between all the invoiced offers (invoiced=1 or the value in hit rate) and all the not invoiced offers.

    Where the conditions for all the not invoiced offers it should be : invoiced=0, but to be counted one time per day for each company if they are more.

    Example: The rows 6,7,8 with offer numbers 29707,29708 and 29709 they have been done on the same date 16/02/2023 and they are with invoiced=0, so I want to count them once.
    Another example are the rows 24,25 and 26, with offer numbers 29689,29690 and 29691. These 3 rows must returns as result 2 (29691 returns one - invoiced=1 plus 29689,29690 which will be counted once because they are invoiced=0 and they have been done on the same day)
    This is not valid for all the offers which have a value invoiced=1 and they have been done in the same day : rows 14 and 15, with offers 296699 and 29700 they are invoiced=1, they must be count twice.
    I hope it is clear.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 11-22-2021, 01:53 PM
  2. [SOLVED] Count occurrences of a value
    By GraeagleBill in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-31-2018, 02:54 PM
  3. [SOLVED] Count occurrences of a value
    By bigband1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-29-2015, 06:57 AM
  4. [SOLVED] Count # of occurrences in range
    By HalPlz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2015, 02:28 AM
  5. [SOLVED] Need a COUNT on occurrences per day
    By graymatterz in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-22-2014, 11:51 AM
  6. [SOLVED] Count number of occurrences but if there are consecutive matches count them as one
    By michaljireht in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-26-2013, 08:26 PM
  7. count Re-occurrences
    By stevekirk in forum Excel General
    Replies: 15
    Last Post: 10-16-2006, 02:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1