+ Reply to Thread
Results 1 to 8 of 8

Flatten a table to a list but keep a link to the original data

  1. #1
    Registered User
    Join Date
    08-21-2020
    Location
    UK
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    16

    Flatten a table to a list but keep a link to the original data

    I have a table of data with multiple rows and columns (100 columns, 400 rows).

    To enable me to report on this data I needed to flatten this table to a list format. I have done this no problem using the pivot table wizard and I'm happy with the results.

    My problem now is that I have two large tables of data that that need to be updated. The original table of data with multiple rows and columns and the flattened list that has come out of the pivot table.

    It is not feasible to update both tables manually nor run the pivot wizard each time there is an update to the original table, which is constant. I need to keep both the original table and flattened list maintained.

    So my question: is there an efficient way to link the original data to the flattened list so that when the original data is updated the flattened list will also be updated?

  2. #2
    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
    80,830

    Re: Flatten a table to a list but keep a link to the original data

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    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.

  3. #3
    Registered User
    Join Date
    08-21-2020
    Location
    UK
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    16

    Re: Flatten a table to a list but keep a link to the original data

    Hi thanks for the reply. I have attached a file with sample data (the actual spreadsheet has hundreds of rows and columns).

    The worksheets have been labelled as follows:


    (1) Master Data sheet (data is named as Table1).

    (2) Pivot Table used to flatten the Master Data.

    (3) Flattened data from the Pivot Table. There is an IF statement in column 4 which I've added just to give a value based upon column 3.



    The values in the Master Data sheet (1) are updated frequently and at the moment I am really struggle to keep both (1) and (3) maintained manually. Constantly updating the Pivot Table (2) is not feasible either as I have that additional column in (3) with the IF, so I need to redo it everytime, even for the smallest update.


    Ultimately what I want to do is find a way to automate updates. For example, when I update a value in the Master Data (1) I want this to be reflected in the Flattened Data table (3).
    Attached Files Attached Files

  4. #4
    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,882

    Re: Flatten a table to a list but keep a link to the original data

    Using Get and Transform found on the Data Tab of your Excel file, you can get the data into the format you require by loading the original table to the PQ editor and unpivoting the columns. Here is the Mcode to do that. When new data is added to the original table. Click on the Refresh all Icon on the Data tab. Go to the output sheet and the table is updated.
    Please Login or Register  to view this content.
    Review PQ
    In the attached file
    Click on any cell in the new table
    On the Data Tab, click on Queries & Connections
    In the right window, double click to open Query
    Review PQ steps

    M-code basics:
    - "let" is the start of a query
    - "in" is the closing of a query
    - each transformation step sits in between those 2 lines
    - each step line is ended by a comma, except the last one
    - "Source" is always the first step (Source Data)
    - After "in" you have the last step referenced
    Attached Files Attached Files
    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

  5. #5
    Registered User
    Join Date
    08-21-2020
    Location
    UK
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    16

    Re: Flatten a table to a list but keep a link to the original data

    Thanks so much for the reply, this is exactly what I needed! I was not aware of this feature in excel - it's really powerful. I've just about got this to work for my use case, with a bit of fine tuning needed:

    • Is it possible to somehow include the IF statement (as I have in the sample xlsx file worksheet 3, column D) into the PQ report so that it automatically populates a column? Or would this still need to be bolted on in the worksheet as it is now.
    • Is it possible to pick and choose which columns are brought into the PQ? I actually have ~100 columns defined in my table and only really need to bring in about half of them to pivot. The sample data was nice and clean and did not include these other columns and in my real data I am getting a lot of data brought in I don't need. I tried only having the ones I need in the LET string but it didn't make any difference.
      I've attached an updated sample file which should make this clearer.
    • Finally, does the PQ ignore blank cells?
    Attached Files Attached Files

  6. #6
    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,882

    Re: Flatten a table to a list but keep a link to the original data

    You can add an If statement by adding a new column and then creating an If then statement.
    You cannot choose which columns to bring in as it brings in a table, however, once in PQ, you can select which columns to keep and which to remove.
    As to blank cells, PQ treats those as null.

    New Mcode

    Please Login or Register  to view this content.
    If you wish to learn more about PQ, then pick up the book "M is for (Data) Monkey" by Ken Puls and Miguel Escobar. Available on Amazon.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-21-2020
    Location
    UK
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    16

    Re: Flatten a table to a list but keep a link to the original data

    Just so I've understood, PQ will bring in all the columns defined in the table, in this case 'Table1'.

    Then on the step #"Removed Other Columns" you have only included the columns you want to see in the report i.e. only the DATAx columns and omitted the columns OTHERDATAx?


    That's really useful to add the IF statement - is it also possible to add other Excel formulas in the same way? In particular a VLOOKUP?

    Thank you for your help.

    Thanks also for the book recommendation - I have ordered it. This feature is something I really want to learn more about.

  8. #8
    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,882

    Re: Flatten a table to a list but keep a link to the original data

    there is no Vlookup function, but what you can do is merge (join) two tables on a particular field (common value) and this does the same as Vlookup except it brings back all matches not just the first one.

    Your first assumption is correct.

+ 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. [SOLVED] Flatten 2D Table with Multiple Headers to a 1D Data Table
    By glidlegolas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2017, 03:41 PM
  2. excel chart - when pasting, link to new data field not the original one
    By Frankximus3 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-09-2016, 03:19 AM
  3. [SOLVED] How to convert flatten table to 2D Excel table
    By martinkabe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2015, 07:22 AM
  4. [SOLVED] How do I link Dropdown List (data validation) with filtering data from a table?
    By Trishux25 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-29-2015, 10:17 PM
  5. Replies: 1
    Last Post: 07-29-2015, 08:36 PM
  6. flatten a crosstab table to list table
    By ieumts in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-28-2014, 04:52 AM
  7. [SOLVED] Flatten cross table with multiple rows
    By tryndamere in forum Excel General
    Replies: 18
    Last Post: 08-16-2013, 12:40 PM

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