+ Reply to Thread
Results 1 to 9 of 9

Merge Sheets Power Query

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    449

    Merge Sheets Power Query

    Hello All,

    I am trying to merge 4 sheets into one using common columns for each unique row.

    See attached.

    These queries are retrieving data from a files on my HD. I added columns "Count" and " Unique BN" to give each row a unique value to avoid duplicates.

    I have highlighted the following columns as common columns:

    Total Amount
    Date Requested

    My hopes was I could use the power query append to slam these together and put them in all of the unique rows into one sheet.
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Merge Sheets Power Query

    Personally, I'd do all transformation in PowerQuery and skip loading tables into sheets. If you can upload sample source files. I can show you steps.

    If that's not feasible. You'd load each table as connection only to PowerQuery.

    Remove all unnecessary columns from each table and make sure all remaining column names match from table to table.

    Then using one of the query, "Append Queries"->three or more.

    Highlight all columns and "Remove Rows"->"Remove Duplicates".

    Change column data type as needed and load to sheet (or data model).

    See attached sample.

    Note: I didn't filter out "null" values, but you may want to.
    Attached Files Attached Files

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Merge Sheets Power Query

    Which columns do you want in the result table?

    This will combine the tables and return only the 4 columns listed.

    let
    Source = Excel.CurrentWorkbook(),
    #"Expanded Content" = Table.ExpandTableColumn(Source, "Content", {"count", "Unique BN", "Total Amount", "Date Requested"}, {"Content.count", "Content.Unique BN", "Content.Total Amount", "Content.Date Requested"})
    in
    #"Expanded Content"
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    449

    Re: Merge Sheets Power Query

    Quote Originally Posted by CK76 View Post
    Personally, I'd do all transformation in PowerQuery and skip loading tables into sheets. If you can upload sample source files. I can show you steps.

    If that's not feasible. You'd load each table as connection only to PowerQuery.

    Remove all unnecessary columns from each table and make sure all remaining column names match from table to table.

    Then using one of the query, "Append Queries"->three or more.

    Highlight all columns and "Remove Rows"->"Remove Duplicates".

    Change column data type as needed and load to sheet (or data model).

    See attached sample.

    Note: I didn't filter out "null" values, but you may want to.

    Sweet, you did it. Question. My source files have duplicate Site ID's across the 4 different sheets so I used the query to create a unique site id (UBN). Do you still want the source files?

    How do I load each table as connection only to powerquery?

    How do I remove columns? Query Editor? When I go into Query Editor, my UBN number and count columns isn't listed.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Merge Sheets Power Query

    Do you still want the source files?
    Only if you need help merging without loading individual tables into sheet.

    How do I load each table as connection only to powerquery?
    Once connection is made, go into editor. Do necessary transformation and click on "Close & Load To". In the menu choose "Only Create Connection".
    Once all transformation and merge etc are done. You can load end result to a sheet or data model.

    How do I remove columns? Query Editor?
    Yes. If you are looking at my sample. You can see where I removed columns in "Applied Steps" pane at the right hand side of editor window.

  6. #6
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    449

    Re: Merge Sheets Power Query

    Quote Originally Posted by CK76 View Post
    Only if you need help merging without loading individual tables into sheet.



    Once connection is made, go into editor. Do necessary transformation and click on "Close & Load To". In the menu choose "Only Create Connection".
    Once all transformation and merge etc are done. You can load end result to a sheet or data model.


    Yes. If you are looking at my sample. You can see where I removed columns in "Applied Steps" pane at the right hand side of editor window.
    Ok . . the issue I've got now is before I do the append, I add two columns (Count and Unique B N) so I can give each row a unique identifier. When I slam them into the Append, they get deleted or disappear. How do I preserve these?

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Merge Sheets Power Query

    You can add Count and Unique BN within PowerQuery.

  8. #8
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    449

    Re: Merge Sheets Power Query

    How?

    For the count column, i put "1" in row 2, and "2" in row 3 and drag it down so it continues the count.

    For the Unique BN, I am concatenating columns.

  9. #9
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Merge Sheets Power Query

    For Count just add custom column -> Add Index Column -> From 1

    For Unique BN. Use concatenation within PowerQuery.

    You can either do it via formula. Or just select both columns to concatenate and right click, choose "Merge Columns".
    This will create new column that will replace original columns.

+ 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. error in power query & power pivot
    By Baldev Kumar in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 01-03-2018, 01:34 AM
  2. SQL -> Power Query SQL
    By happydays886 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-14-2017, 11:56 AM
  3. Power Query From Within VBA
    By rabend in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2016, 07:34 AM
  4. Power Query, merge 2 or more large files in one
    By Remphan in forum Excel General
    Replies: 0
    Last Post: 03-02-2016, 04:28 AM
  5. Power Query, merge 2 or more large files in one
    By Remphan in forum Excel General
    Replies: 0
    Last Post: 03-02-2016, 03:30 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