Closed Thread
Results 1 to 11 of 11

count unique values per month

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Atlantis
    MS-Off Ver
    2013
    Posts
    17

    count unique values per month

    I have a SQL query table with order data, and I am trying to figure out how many of each type of order occurred each month. each order can have multiple rows. I am having difficulties getting it to count only unique orders.

    Order# Date Type
    1 6/1/16 OoC
    1 6/1/16 OoC
    2 5/16/16 HNA 213
    5 4/13/16 HNA 456
    3 6/12/16 ACC

    How many OoC orders in June? the answer is 1.
    How many HNA orders in April? The answer is 1.


    the Attached Sample is a small amount of data compared to the actual table, everything is on a single sheet and only has a small amount of the 3 columns that are needed. The actual is a large table that will grow as data is added from the query.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,913

    Re: count unique values per month

    In I2, =COUNTIFS($C$2:$C$16,"HNA*",$B$2:$B$16,">3/31/2016",$B$2:$B$16,"<5/1/2016")
    Change up the dates and criteria for each of the other cells using this as a model.

    Here is a link on using Countifs. https://www.ablebits.com/office-addi...iple-criteria/
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    06-26-2015
    Location
    Atlantis
    MS-Off Ver
    2013
    Posts
    17

    Re: count unique values per month

    Thanks Alan, But this ignores column A, where the order numbers are listed multiple times. I want to count each order number only 1 time. If I put your formula into J2, (HNA for May) and adjust the dates range, it gives a value of 5, but in column A they are all the same order number. so the correct value should be 1.

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

    Re: count unique values per month

    This solution employees a helper column (D), which may be hidden for aesthetic purposes, which has the formula: =COUNTIFS(A$2:A2,A2)
    The array entered formula* that fills in the table (I2:K4) is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    *Array entered formulas are confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Note: the months listed in I1:K1 are now dates and the cells are formatted "mmmm".
    Let me know if you have any questions.

    Edit: I noticed an error in the formula, however I am not sure if it relates to the reason that the formula didn't work on actual data as stated in post #5.
    Attached Files Attached Files
    Last edited by JeteMc; 08-08-2016 at 04:02 PM. Reason: Correcting an error in formula
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    06-26-2015
    Location
    Atlantis
    MS-Off Ver
    2013
    Posts
    17

    Re: count unique values per month

    Is there any way to avoid a helper column? The Actual is a much larger table derived from a SQL Query that refreshed and adds new rows.
    Also, i couldn't get the Array formula to work when i tried to adjust it to fit the Actual. I tried a countifs, that seems to work.
    This is the Countifs formula from the Actual, where the helper column is AP; -C:C is the date column, M:M is the Type Column, and AP:AP is the helper column.
    =COUNTIFS(PSDATA!C:C,">=7/1/16",PSDATA!C:C,"<=7/31/16",PSDATA!M:M,"HNA*",PSDATA!AP:AP,"=1")


    I suppose I could add an "ISblank" to the helper column formula, and just propagate it down a couple thousand rows...

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: count unique values per month

    Try this...

    Data Range
    E
    F
    G
    H
    1
    April
    May
    June
    2
    HNA
    0
    1
    1
    3
    ACC
    1
    2
    2
    4
    OoC
    0
    0
    1


    This array formula** entered in F2:

    =SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH($E2,$C$2:$C$16)),IF(TEXT($B$2:$B$16,"mmmm")=F$1,MATCH($A$2:$A$16,$A$2:$A$16,0))),ROW(A$2:A$16)-ROW(A$2)+1),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy across to H2 then down to F4:H4.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    06-26-2015
    Location
    Atlantis
    MS-Off Ver
    2013
    Posts
    17

    Re: count unique values per month

    Both JeteMc and Tony Valco have valid solutions. I think I will work to get Tony's working in the Actual Spreadsheet since it doesn't require a 'helper' column. I intend to keep them both handy ans I will be able to use them in various spreadsheets I work with.
    Thanks to you both.
    Solved.

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count unique values per month

    d2 =if(countif($C$2:$C2,$C2)=1,countif($C$2:$C2,$C2),"") and drag down.

    after that a pivot table.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: count unique values per month

    You're welcome. Thanks for the feedback!

  10. #10
    Registered User
    Join Date
    03-15-2013
    Location
    Naples, FL
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: count unique values per month

    Hi, can someone help me to count unique values/names per month? Thanks a lot :-)
    Attached Images Attached Images
    Attached Files Attached Files

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,226

    Re: count unique values per month

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Count of unique contractors that were paid during the month
    By DD1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-19-2015, 10:11 PM
  2. [SOLVED] Unique Total Value Count per Unique Lookup Values
    By KnightVision in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-02-2014, 05:03 AM
  3. Count number of unique cells if month =
    By BM02GAN in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-25-2014, 12:31 PM
  4. [SOLVED] Formula to Count Unique Customer by Month
    By byankton in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-19-2013, 12:39 AM
  5. Count unique for specific month
    By Bob@Sun in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-17-2011, 02:52 PM
  6. Count unique days within month
    By jirib in forum Excel General
    Replies: 7
    Last Post: 08-26-2010, 06:12 PM
  7. Replies: 17
    Last Post: 08-24-2009, 08:58 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