+ Reply to Thread
Results 1 to 8 of 8

Data Import does not add to data model

  1. #1
    Registered User
    Join Date
    10-08-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Data Import does not add to data model

    Hi,

    I'm hoping this is something simple. I'm not great with VBA and still feeling my way around other people code snippets and making things work for me.

    I have a macro which connects and queries multiple external tables into a pivot table in my spreadsheet.
    This works fine.
    The issue is that I need to import that data in to the data model in order to be able to use a specific option in the pivot table (summarise the value using "Distinct Count")

    This option is not available unless the data is in the data model.

    Any help appreciated!
    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: Data Import does not add to data model

    Instead of adding query directly to PivotCache. Use Workbook.Connections.Add2 method to load to data model/powerpivot.

    See link for details.
    https://msdn.microsoft.com/en-us/lib...ions.add2.aspx

  3. #3
    Registered User
    Join Date
    10-08-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Data Import does not add to data model

    Thanks CK76,

    Yes, I had seen that option but I have know idea really how to modify the code.
    I found most of it elsewhere and made a few basic changes.

    I can spend more time trying to figure it out.
    Main issue I think for me will be how to pass the array values (multiple files) to the connection string.

    Thanks!

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

    Re: Data Import does not add to data model

    Just leverage PowerQuery (Get and transform).

    You can use macro recorder to record your process of putting connection into data model. This will give you base code.

    As for multiple files... are they all in same structure and being merged into single data model. Or are they different tables that are related via key column?

  5. #5
    Registered User
    Join Date
    10-08-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Data Import does not add to data model

    The files are mostly the same but occasionally a different number of columns.
    So I query for specific column header names and just import those (from one sheet in each file)

    I'll keep at it. I usually get there in the end. Thanks again.

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

    Re: Data Import does not add to data model

    Refer to the link for how to merge multiple file using PowerQuery. See post#6
    https://www.excelforum.com/excel-gen...workbooks.html

    Note that you'll need to modify steps a bit, as you have to choose columns.

  7. #7
    Registered User
    Join Date
    10-08-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Data Import does not add to data model

    Thanks, I'll take a look.

  8. #8
    Registered User
    Join Date
    10-08-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Data Import does not add to data model

    Just to close this out.

    I found out that a simple 'double click' on the "Grand Total" value of my existing pivot, recreated all the data from that pivot table in a new table in a new sheet.

    All I did then was macro record myself doing this(.ShowDetail=True), renaming the new sheet, deleting the old Pivot table and recreating a new pivot from that new table data (Choosing "add data to the Data Model')

    Certainly not the most efficient way to do this but I got what I needed.

    Thanks.

+ 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. Calculated field greyed out after adding data to the data model
    By paula10 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 02-20-2017, 09:12 AM
  2. Selecting Column Data in Pivot Table (from Data model)
    By derickz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2016, 11:35 PM
  3. Adding more data into data model
    By stephme55 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-12-2016, 07:32 PM
  4. Data Model
    By vjharry in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-18-2015, 09:34 AM
  5. Replies: 0
    Last Post: 03-26-2015, 10:37 AM
  6. Excel 2007 : Grab data from model run data sheets
    By rachelegan in forum Excel General
    Replies: 1
    Last Post: 09-14-2010, 10:46 AM
  7. Replies: 13
    Last Post: 08-08-2006, 05:05 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