Results 1 to 12 of 12
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038

    Raw Data to Matrix (4-step data transformation process)

    Hello Experts:

    I need some assistance with transforming some raw data into a matrix.

    Background:
    - In the attached XLS, I illustrate the *transformation process* in four steps.
    - Step 1 is the true "raw data". These values can be found in the attached DB (table "tblRawData").
    - Step 2 illustrates a simple count (grouped) with field names in ASC order. This view can be found in query "Query - Step 2".
    - Step 3 (in Excel) was *manually* created. Here, I simply copied the distinct source references into either column H or I or J or K.
    - Step 4 (in Excel) was also *manually* created. Specifically, I now added a "header row" which shows the four distinct source references (row 3 in Excel). Now, however, any populated source reference is replaced with an "x" in the matrix.

    Here's what I need some help with (ideally in Access):


    - I'd like to automate the process which ultimately allows me to get to "Step 4". I'm not sure if "Step 3" can be skipped based on the query "Query - Step 2".
    - If needed, I'm okay with using some form of "helper queries" in order to automate the process. Ideally though, I'd like to keep the number of helper queries/functions to a minimum.
    - Finally, please keep in mind that all information (both in Excel and Access files are merely sample data). That is, my actual data source may include 10 different source references and has hundreds of records/values. That said, the transformation process must be *smart enough* to search for the distinct source references when placing them into the header row (Excel Step 4).

    Thousand thanks in advance for assisting me (either w/ the required queries or VBA development) in database format!!

    Cheers,
    Tom

    P.S. Attached are the Excel and Access files (in zipped format)
    Attached Thumbnails Attached Thumbnails Raw Data to Matrix.jpg  
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    looks like 3 pivot tables.
    record a macro , the run the pivot, then edit the code to allow for generic names and data volume.
    then open the raw data, and run the macro

  3. #3
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    ranman256... I think so... would you be willing to provide additional info as to how to create the macros, pivots, VBA, etc?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    in excel, turn on macros:
    menu: file, options, (left pane) customize ribbon
    (right pane) checkmark DEVELOPER
    OK


    Now macros are available: menu: developer, RECORD macro
    (to start recording)

    to make a pivot,
    in a sheet with data , put cursor in cell a1,
    menu: insert , pivot table
    OK, (accept default)
    (in far right pane) grab fields (top)
    drag them down to the place you want ,either ROWS, COLUMNS , VALUES

    STOP RECORDING once you end the pivot

  5. #5
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    ranman256... so, this couldn't be done in Access?

  6. #6
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Quick follow-up... I get the pivot table in Excel. However, what about the more important steps 3 and 4?

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    You could try something like this (untested)
    Code:
    TRANSFORM First(step1.Expr1) AS FirstOfExpr1 
    SELECT step1.Fieldname 
    FROM   (SELECT tblRawData.Fieldname, 
                   tblRawData.Source, 
                   "x" AS Expr1 
            FROM   tblRawData 
            GROUP  BY tblRawData.Fieldname, 
                      tblRawData.Source, 
                      "x") AS step1 
    GROUP  BY step1.Fieldname 
    ORDER  BY step1.Fieldname 
    PIVOT step1.Source;  

  8. #8
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    kd2017 -- is this done in a module or a form? Not fully clear how to use your function. Any additional help would be greatly appreciated. Thank you!

  9. #9
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    It's an access sql query that transforms the data from your table in "step 1" to the desired output in "step 4"

    Go to Query Design to make a new query. On the top left of the ribbon click 'SQL View', and copy and paste the code there. Then hit Run.

  10. #10
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Wow... this this totally amazing!!!!! Your query solved it beautifully. I'm super impressed!!!!!

  11. #11
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Here is the same thing done using Excel Power Query.

    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1", "Column2"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each "x"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Column1]), "Column1", "Custom"),
        #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Column2", "FieldName"}}),
        #"Sorted Rows" = Table.Sort(#"Renamed Columns",{{"FieldName", Order.Ascending}})
    in
        #"Sorted Rows"
    Attached Files Attached Files

  12. #12
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Thank you kd2017... 'much appreciated!

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

Similar Threads

  1. Replies: 10
    Last Post: 02-23-2021, 04:51 PM
  2. Replies: 3
    Last Post: 08-05-2019, 02:41 PM
  3. Replies: 1
    Last Post: 06-20-2019, 02:10 PM
  4. DB Design starting first model , with Matrix data from Excel
    By warlock916 in forum Database Design
    Replies: 6
    Last Post: 01-11-2016, 01:47 AM
  5. multi-step process with click of button
    By pg13Reader in forum Forms
    Replies: 4
    Last Post: 12-12-2011, 11:12 AM

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