Results 1 to 3 of 3

Power Query: Appending empty data set

Threaded View

  1. #1
    Registered User
    Join Date
    03-08-2019
    Location
    Denmark
    MS-Off Ver
    Office 365
    Posts
    57

    Exclamation Power Query: Appending empty data set

    Hi,

    I am struggling with a Power Query element in Excel 2013.

    Basically, I am trying to import a set of data (let's call it data set 1) from another Excel file, clean it up by replacing a space and a dash in the ID column (formatted as "010180-1210"), change the column names from "id" and "name" to "ID" and "Name", and change the number formatting of "ID" column, before before appending it into another query (from another data set, say data set 2).

    The structure, column names (except for "ID" and "Name") and formatting of the two sets of data are completely different, but the issue is that while data set 2 will always contain data, data set 1 might not always do.

    In the cases where data set 1 does not contain data, the query succeeds with removing columns because of the "MissingField.Ignore" argument, but fails in replacing values and changing number formatting.

    So, I am looking for a similar argument (or other solution) that allows me to basically append nothing if data set 1 is empty, but ensures that the query does not fail (since the appended query fails in that event too).

    I have included the M code below (I know it could be a lot cleaner but bear with me). Thanks in advance.


    let
        Source = Excel.Workbook(File.Contents("G:\File1.xlsx"), null, true),
        #"Test version1_Sheet" = Source{[Item="Test version1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(#"Test version1_Sheet"),
        #"Removed Other Columns" = Table.SelectColumns(#"Promoted Headers",{"id", "name", "salary"},MissingField.Ignore),
        #"Replaced Value" = Table.ReplaceValue(#"Removed Other Columns"," ","",Replacer.ReplaceText,{"id"}),
        #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","-","",Replacer.ReplaceText,{"id"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value1",{{"id", Int64.Type}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"id", "ID"}, {"name", "Name"}})
    in
        #"Renamed Columns"
    Last edited by Phil123456789; 02-02-2020 at 05:28 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel Power Query Refresh or Access Query - 2nd Query Run is faster
    By Steveapa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2020, 10:16 AM
  2. [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
  3. Appending Charts using Power Query Excel 2016
    By STokhi1 in forum Excel Charting & Pivots
    Replies: 13
    Last Post: 07-02-2018, 07:30 AM
  4. 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
  5. Replies: 0
    Last Post: 04-05-2018, 01:16 AM
  6. Appending Power Query in VBA
    By randallrosa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-05-2017, 03:48 AM
  7. Replies: 2
    Last Post: 11-17-2010, 06:59 PM

Tags for this Thread

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