+ Reply to Thread
Results 1 to 3 of 3

Power Query: A Changing Column Name

  1. #1
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    810

    Power Query: A Changing Column Name

    Hi,

    I am a new user of Power Query and so have a, hopefully, simple question.

    I have created a query in the PQ Editor (PQE) that creates a Table in a workbook based on data in a source worksheet in another workbook.

    The idea is that each month I will paste the latest month-end data over the data in the source worksheet and then update the query to refresh the Table.

    A wrinkle with this is that the last column of the data in the source worksheet has as its header name the month-end date of the report. So last month it was "30-06-2020" and next month it will be "31-07-2020".

    This causes a problem because when refreshing the data for 31-07-2020 the query looks for "30-06-2020" as the name for the last column and fails when it doesn't find it

    Is there a dynamic way to manage in the PQE the changing header in the last column or is the solution simply manually to adjust the header in the source data?

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    03-18-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2016 / 2019
    Posts
    251

    Re: Power Query: A Changing Column Name

    Hi,

    there are few ways in managing dynamic column in Power Query, Table.ColumnNames is the M code that we can create dynamic column header

    actually i am not sure exactly what is your issue, you cut and paste a new data to the table for refreshing ? actually you can create a connection instead so that the table name will not be changed

    Best that you upload a sample data sheets and tell us exactly what is your issue and what you want to achieve
    Christopher Yap

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

    Re: Power Query: A Changing Column Name

    There are few ways to handle it. My preference is never to use date/number string in header... but if that can't be avoided....

    Use Table.ColumnNames(Source) to generate list of column names before any transformations are applied.

    Then set some variable to ... = List.Last(ColumnNames)
    This will supply last column name dynamically.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

+ 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. Replies: 10
    Last Post: 06-25-2020, 12:19 AM
  2. Power Query - Date List with changing variable
    By Steveapa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-17-2020, 04:54 PM
  3. Power Query - Date List with changing variable
    By Steveapa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2020, 12:27 PM
  4. Power Query: Updating a query based on changing tables
    By cheesehead101 in forum Excel General
    Replies: 1
    Last Post: 12-16-2019, 06:54 PM
  5. [SOLVED] Power Pivot does not load new column added in Power query
    By ibuhary in forum Excel General
    Replies: 12
    Last Post: 02-19-2019, 03:53 AM
  6. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  7. Power Query and adding a column changing dates
    By ammartino44 in forum Excel General
    Replies: 0
    Last Post: 01-09-2018, 05:24 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