Results 1 to 4 of 4
  1. #1
    geocan2006 is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    May 2016
    Posts
    34

    Unique sort with location ID

    I need to solve below puzzle, example Unique sort with location ID
    I hope lots of folks can benefit from this query
    Thanks


    Table1
    Model Location Qtty
    RedHat Bin1 5
    RedHat Bin7 2
    RedHat Bin8 7
    BlackHat Bin2 2
    BlackHat Bin1 4
    BlackHat Bin4 6
    YellowHat Bin5 6




    Query1
    Model Look1 Look2 Look3
    RedHat Bin1 =5 Bin7 =2 Bin8 =7
    BlackHat Bin2 =2 Bin1 =4 Bin4 =6
    YellowHat Bin5 =6

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in the table that holds the Locations, add a sort column
    or
    sort in the query with: Val([location])
    (using the number in the location)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If Location contains text data that begins with alpha characters, Val([Location]) will not return the numbers.

    You need sequence numbering for each Model group. This sequence number field will be the ColumnHeader for a CROSSTAB query.

    Why bother including the word "Bin" in the data? Is there ever anything else but "Bin"? Following suggestion uses table that does not include the word "Bin" in the table data. And Location field is a number type.

    TRANSFORM First("Bin" & [Location] & " = " & [Qtty]) AS Data
    SELECT Table1.Model
    FROM Table1
    GROUP BY Table1.Model
    PIVOT "Look" & DCount("*","Table1","Model='" & [Model] & "' AND Location<" & [Location])+1;

    This version deals with Location as text field with "Bin" in the data:

    TRANSFORM First([Location] & " = " & [Qtty]) AS Data
    SELECT Table1.Model
    FROM [Table1]
    GROUP BY Table1.Model
    PIVOT "Look" & DCount("*","[Table1]","Model='" & [Model] & "' AND Val(Replace([Location], 'Bin', ''))<" & Val(Replace([Location], "Bin", "")))+1;

    If the number of possible bins never exceeds 9 then the Val() and Replace() functions are not necessary. Also, if the sequence count exceeds 9 the columns will not sort in proper order with the "Look" text prefix. Sorting on text is less efficient and performance might be noticeably slower with large dataset.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    geocan2006 is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    May 2016
    Posts
    34

    Red face Solved

    Quote Originally Posted by June7 View Post
    If Location contains text data that begins with alpha characters, Val([Location]) will not return the numbers.

    You need sequence numbering for each Model group. This sequence number field will be the ColumnHeader for a CROSSTAB query.

    Why bother including the word "Bin" in the data? Is there ever anything else but "Bin"? Following suggestion uses table that does not include the word "Bin" in the table data. And Location field is a number type.

    TRANSFORM First("Bin" & [Location] & " = " & [Qtty]) AS Data
    SELECT Table1.Model
    FROM Table1
    GROUP BY Table1.Model
    PIVOT "Look" & DCount("*","Table1","Model='" & [Model] & "' AND Location<" & [Location])+1;

    This version deals with Location as text field with "Bin" in the data:

    TRANSFORM First([Location] & " = " & [Qtty]) AS Data
    SELECT Table1.Model
    FROM [Table1]
    GROUP BY Table1.Model
    PIVOT "Look" & DCount("*","[Table1]","Model='" & [Model] & "' AND Val(Replace([Location], 'Bin', ''))<" & Val(Replace([Location], "Bin", "")))+1;

    If the number of possible bins never exceeds 9 then the Val() and Replace() functions are not necessary. Also, if the sequence count exceeds 9 the columns will not sort in proper order with the "Look" text prefix. Sorting on text is less efficient and performance might be noticeably slower with large dataset.
    The 2nd option worked like a charm,
    Best regards!!!

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

Similar Threads

  1. Unique sort and sum
    By geocan2006 in forum Queries
    Replies: 5
    Last Post: 02-07-2018, 12:25 PM
  2. Replies: 1
    Last Post: 04-07-2014, 02:59 AM
  3. Replies: 22
    Last Post: 03-03-2013, 02:00 PM
  4. sort filter, doesn't sort everything
    By deso in forum Queries
    Replies: 4
    Last Post: 01-25-2013, 05:27 AM

Tags for this Thread

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