Results 1 to 6 of 6
  1. #1
    pandorah is offline Novice
    Windows XP Office 365
    Join Date
    Feb 2021
    Posts
    13

    Query - count summary while excluding specific text

    Hi there, I'm trying to do a query on a table to count the number of fields with data while excluding one specific type of data. I have attached an example in excel to illustrate what I'm trying to do. In this example, I want to combine each unique 'Item' into one line and count the number of 'Pieces' on each individual 'day'. However, I want to exclude any cell that says "Red" from that count. The bottom two rows show the output I'm looking for. Can you help me figure out the best way to do this? Thank you.
    Attached Files Attached Files

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    if this is supposed to represent an Access table then I'm afraid you have a major task ahead - one I don't want to get involved with.

    If on the other hand you normalise your data then the problem is trivial

    Normalised your data would look more like the

    Item....Piece...Day........colour
    shirt.....1........sunday...red
    shirt.....1........monday...purple
    shirt.....1........tuesday...purple
    shirt.....1........wedensday...purple
    shirt.....1........thursday...purple
    shirt.....1........friday...purple
    shirt.....1........saturday...red
    shirt.....3........sunday...red
    shirt.....3........monday...red
    shirt.....3........tueday...green
    etc

    then you query would be something like

    SELECT item, Day, count(*)
    FROM myTable
    WHERE colour<>"Red"

    which you can then present horizontally by converting the query to a crosstab

  3. #3
    pandorah is offline Novice
    Windows XP Office 365
    Join Date
    Feb 2021
    Posts
    13
    Unfortunately the current table is imported from another system and the data is horizontal as represented in my attachment. I can't change how the data arrives. Is there is a way to normalize it the way you suggest via access once imported? If not, then thank you anyway and I will wait and see if someone else is willing to help.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Is there is a way to normalize it the way you suggest via access once imported?
    create your table then use an append query to append each column in turn to the table. You can do this in one hit using a union query - which if this is just an occasional requirement you can use instead of the table - something like this union query can be turned into an append query

    SELECT item, Piece, Sunday as Day, colour FROM xlTable
    UNION ALL SELECT item, Piece, Monday, colour FROM xlTable
    UNION ALL SELECT item, Piece, Tuesday, colour FROM xlTable
    etc

  5. #5
    pandorah is offline Novice
    Windows XP Office 365
    Join Date
    Feb 2021
    Posts
    13
    Thank you for the help

  6. #6
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You can normalize your data by bringing it into Power Query and then unpivoting the data

    Here is the Mcode to make that happen

    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Item", "Day:"}, "Attribute", "Value")
    in
        #"Unpivoted Other Columns"
    If you want to take it to the next step and do the calculation in Power query then

    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Item", "Day:"}, "Attribute", "Value"),
        #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "Red")),
        #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Item", "Attribute"}, {{"Count", each Table.RowCount(_), Int64.Type}})
    in
        #"Grouped Rows"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 09-29-2016, 06:47 AM
  2. Replies: 5
    Last Post: 04-23-2015, 10:23 AM
  3. Report summary count with multiple criteria
    By crimedog in forum Reports
    Replies: 1
    Last Post: 09-19-2014, 01:33 PM
  4. Performing a count of specific text in report
    By Bobwords in forum Reports
    Replies: 3
    Last Post: 06-20-2014, 01:35 PM
  5. Replies: 6
    Last Post: 02-13-2014, 11:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums