Home

Formatting Issue (Getting data from 1 column into 7 columns)

%3CLINGO-SUB%20id%3D%22lingo-sub-855904%22%20slang%3D%22en-US%22%3EFormatting%20Issue%20(Getting%20data%20from%201%20column%20into%207%20columns)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-855904%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%20I'm%20having%20a%20devil%20of%20a%20problem%20trying%20to%20import%20data%20from%20the%20web%20and%20getting%20it%20into%20Excel%20in%20roughly%20the%20same%20columned%20format.%26nbsp%3B%20I'm%20copying%20the%20relevant%20data%20(which%20is%20information%20that%20I've%20put%20together%20using%20various%20filter%20selections%20on%20a%20specific%20web%20site)%20and%20then%20pasting%20it%20into%20Excel.%26nbsp%3B%20When%20I%20do%20this%2C%20all%20of%20the%20data%20is%20shown%20in%20one%20long%20column.%26nbsp%3B%20It%20looks%20roughly%20like%20this%20(using%20the%20info%20from%20just%202%20companies)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELoving%20Care%20Agency%2C%20Inc.%3C%2FP%3E%3CP%3EHealth%20Services%2C%20Hospital%20%26amp%3B%20Health%20Care%3C%2FP%3E%3CP%3E%24200%20Million%20-%20%241%20Billion%3C%2FP%3E%3CP%3E(201)%20403-9300%3C%2FP%3E%3CP%3EHasbrouck%20Heights%2C%20NJ%3C%2FP%3E%3CP%3Elovingcareagency.com%3C%2FP%3E%3CP%3E1971%3C%2FP%3E%3CP%3EFrontline%20Consulting%20Services%20Inc.%3C%2FP%3E%3CP%3EBusiness%20Services%2C%20Information%20Technology%20and%20Services%3C%2FP%3E%3CP%3E%24100%20Million%20-%20%24200%20Million%3C%2FP%3E%3CP%3E(704)%20510-1998%3C%2FP%3E%3CP%3ECharlotte%2C%20NC%3C%2FP%3E%3CP%3Efcs-inc.com%3C%2FP%3E%3CP%3E1996%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20get%20this%20data%20into%207%20columns%20(Company%20Name%3B%20Industry%3B%20Yearly%20Revenue%3B%20Phone%20%23%3B%20Location%3B%20Web%20Site%3B%20Year%20Founded).%20Using%20%22Text%20to%20Columns%22%20is%20no%20help%20as%20there%20are%20no%20delimiters%20(commas%2C%20tabs%2C%20spaces%2C%20etc.).%26nbsp%3B%20Is%20there%20any%20way%20to%20get%20this%20data%20into%20the%20same%20columns%20as%20they%20are%20presented%20on%20the%20original%20web%20site%2C%20or%20do%20I%20have%20to%20manually%20insert%20a%20delimiter%20after%20each%20line%20of%20data%3F%26nbsp%3B%20Any%20help%20will%20be%20GREATLY%20appreciated.%26nbsp%3B%20Thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-855904%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-855927%22%20slang%3D%22en-US%22%3ERe%3A%20Formatting%20Issue%20(Getting%20data%20from%201%20column%20into%207%20columns)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-855927%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F409063%22%20target%3D%22_blank%22%3E%40JeffJ625%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20use%20Power%20Query%20to%20get%20the%20data%20in%20the%20desired%20format.%3C%2FP%3E%3CP%3ETo%20do%20so%2C%20follow%20these%20steps...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EConvert%20your%20one%20column%20Web%20Data%20into%20an%20Excel%20Table%20if%20not%20already%20formatted%20as%20an%20Excel%20Table%20and%20to%20do%20that%20select%20your%20data%20and%20press%20Ctrl%2BT%20and%20uncheck%20the%20CheckBox%20for%20%22My%20table%20has%20headers%22%20and%20click%20OK.%3C%2FLI%3E%3CLI%3ERename%20the%20Excel%20Table%20you%20just%20created%20with%20%22WebData%22.%3C%2FLI%3E%3CLI%3ENow%20go%20to%20Data%20Tab%20and%26nbsp%3B%20under%20Get%20%26amp%3B%20Transform%20Data%20group%2C%20click%20on%20Get%20Data%20--%26gt%3B%20From%20Other%20Sources%20--%26gt%3B%20Blank%20Query.%20This%20will%20open%20Power%20Query%20Editor%20Window.%3C%2FLI%3E%3CLI%3EOn%20Power%20Query%20Editor%20Window%20--%26gt%3B%20View%20--%26gt%3B%20and%20click%20on%20Advanced%20Editor%20and%20delete%20whatever%20you%20see%20that%20and%20paste%20the%20query%20given%20below%20in%20the%20Advanced%20Editor%20and%20click%20on%20OK.%3C%2FLI%3E%3CLI%3ENow%20go%20to%20Home%20Tab%20on%20Power%20Query%20Editor%20Window%20and%20click%20on%20Close%20%26amp%3B%20Load.%20This%20will%20load%20the%20table%20with%20data%20in%20the%20desired%20format%20into%20a%20new%20sheet.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CSTRONG%3EQuery%3A%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22WebData%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20%23%22Removed%20Blank%20Rows%22%20%3D%20Table.SelectRows(Source%2C%20each%20not%20List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_)%2C%20%7B%22%22%2C%20null%7D)))%2C%0A%20%20%20%20%23%22Changed%20Type%22%20%3D%20Table.TransformColumnTypes(%23%22Removed%20Blank%20Rows%22%2C%7B%7B%22Column1%22%2C%20type%20any%7D%7D)%2C%0A%20%20%20%20%23%22Added%20Index%22%20%3D%20Table.AddIndexColumn(%23%22Changed%20Type%22%2C%20%22Index%22%2C%200%2C%201)%2C%0A%20%20%20%20%23%22Inserted%20Modulo%22%20%3D%20Table.AddColumn(%23%22Added%20Index%22%2C%20%22Modulo%22%2C%20each%20Number.Mod(%5BIndex%5D%2C%207)%2C%20type%20number)%2C%0A%20%20%20%20%23%22Pivoted%20Column%22%20%3D%20Table.Pivot(Table.TransformColumnTypes(%23%22Inserted%20Modulo%22%2C%20%7B%7B%22Modulo%22%2C%20type%20text%7D%7D%2C%20%22en-IN%22)%2C%20List.Distinct(Table.TransformColumnTypes(%23%22Inserted%20Modulo%22%2C%20%7B%7B%22Modulo%22%2C%20type%20text%7D%7D%2C%20%22en-IN%22)%5BModulo%5D)%2C%20%22Modulo%22%2C%20%22Column1%22)%2C%0A%20%20%20%20%23%22Removed%20Columns%22%20%3D%20Table.RemoveColumns(%23%22Pivoted%20Column%22%2C%7B%22Index%22%7D)%2C%0A%20%20%20%20%23%22Filled%20Up%22%20%3D%20Table.FillUp(%23%22Removed%20Columns%22%2C%7B%221%22%2C%20%222%22%2C%20%223%22%2C%20%224%22%2C%20%225%22%2C%20%226%22%7D)%2C%0A%20%20%20%20%23%22Filtered%20Rows%22%20%3D%20Table.SelectRows(%23%22Filled%20Up%22%2C%20each%20(%5B0%5D%20%26lt%3B%26gt%3B%20null))%2C%0A%20%20%20%20%23%22Renamed%20Columns%22%20%3D%20Table.RenameColumns(%23%22Filtered%20Rows%22%2C%7B%7B%220%22%2C%20%22Company%20Name%22%7D%2C%20%7B%221%22%2C%20%22Industry%22%7D%2C%20%7B%222%22%2C%20%22Yearly%20Revenue%22%7D%2C%20%7B%223%22%2C%20%22Phone%23%22%7D%2C%20%7B%224%22%2C%20%22Location%22%7D%2C%20%7B%225%22%2C%20%22Website%22%7D%2C%20%7B%226%22%2C%20%22Year%20Founded%22%7D%7D)%0Ain%0A%20%20%20%20%23%22Renamed%20Columns%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20if%20you%20are%20getting%20the%20web%20data%20through%20the%20From%20Web%20under%20Get%20%26amp%3B%20Transformed%20Data%20Group%2C%20you%20may%20tweak%20the%20existing%20query%20to%20get%20the%20data%20in%20the%20desired%20format.%3C%2FP%3E%3C%2FLINGO-BODY%3E
JeffJ625
New Contributor

Hello. I'm having a devil of a problem trying to import data from the web and getting it into Excel in roughly the same columned format.  I'm copying the relevant data (which is information that I've put together using various filter selections on a specific web site) and then pasting it into Excel.  When I do this, all of the data is shown in one long column.  It looks roughly like this (using the info from just 2 companies):

 

Loving Care Agency, Inc.

Health Services, Hospital & Health Care

$200 Million - $1 Billion

(201) 403-9300

Hasbrouck Heights, NJ

lovingcareagency.com

1971

Frontline Consulting Services Inc.

Business Services, Information Technology and Services

$100 Million - $200 Million

(704) 510-1998

Charlotte, NC

fcs-inc.com

1996

 

I need to get this data into 7 columns (Company Name; Industry; Yearly Revenue; Phone #; Location; Web Site; Year Founded). Using "Text to Columns" is no help as there are no delimiters (commas, tabs, spaces, etc.).  Is there any way to get this data into the same columns as they are presented on the original web site, or do I have to manually insert a delimiter after each line of data?  Any help will be GREATLY appreciated.  Thank you.

9 Replies

@JeffJ625 

You may use Power Query to get the data in the desired format.

To do so, follow these steps...

 

  1. Convert your one column Web Data into an Excel Table if not already formatted as an Excel Table and to do that select your data and press Ctrl+T and uncheck the CheckBox for "My table has headers" and click OK.
  2. Rename the Excel Table you just created with "WebData".
  3. Now go to Data Tab and  under Get & Transform Data group, click on Get Data --> From Other Sources --> Blank Query. This will open Power Query Editor Window.
  4. On Power Query Editor Window --> View --> and click on Advanced Editor and delete whatever you see that and paste the query given below in the Advanced Editor and click on OK.
  5. Now go to Home Tab on Power Query Editor Window and click on Close & Load. This will load the table with data in the desired format into a new sheet.

 

Query:

 

let
    Source = Excel.CurrentWorkbook(){[Name="WebData"]}[Content],
    #"Removed Blank Rows" = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Blank Rows",{{"Column1", type any}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 7), type number),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-IN")[Modulo]), "Modulo", "Column1"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
    #"Filled Up" = Table.FillUp(#"Removed Columns",{"1", "2", "3", "4", "5", "6"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([0] <> null)),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"0", "Company Name"}, {"1", "Industry"}, {"2", "Yearly Revenue"}, {"3", "Phone#"}, {"4", "Location"}, {"5", "Website"}, {"6", "Year Founded"}})
in
    #"Renamed Columns"

 

 

Also, if you are getting the web data through the From Web under Get & Transformed Data Group, you may tweak the existing query to get the data in the desired format.

@Subodh_Tiwari_sktneer 

Bit another transformation

let

    ColumnNames = {"Company Name", "Industry", "Yearly Revenue", "Phone#", "Location", "Website", "Year Founded"},
    ItemsInGroup =7,

    Source = Excel.CurrentWorkbook(){[Name="WebData"]}[Content],
    RemoveNulls = Table.SelectRows(
        Source,
        each not List.IsEmpty(
            List.RemoveMatchingItems(Record.FieldValues(_), {"", null})
        )
    ),
    GroupsToLists = Table.FromList(
        List.Split(
            RemoveNulls[Column1],
            ItemsInGroup
        ),
        Splitter.SplitByNothing()
    ),
    GroupsToRecords = Table.ReplaceValue(
        GroupsToLists,
        each [Column1] ,
        each Record.FromList([Column1],ColumnNames),
        Replacer.ReplaceValue,{"Column1"}
    ),
    ExpandRecords = Table.ExpandRecordColumn(
        GroupsToRecords,
        "Column1", ColumnNames, ColumnNames
    )
in
    ExpandRecords

@Subodh_Tiwari_sktneer 

 

Subodh (and Sergei)...thank you very much for responding.  I've tried both of your Power Querys and get the same message:

 

Expression.Error: We couldn't find an Excel table named 'WebData".

Details:

     WebData

 

What am I doing wrong?

- Jeff

@JeffJ625 

WebData is the table with raw data which you shall create. Select all raw data in column A, press Ctrl+T and create the table.

On ribbon you will stay on Table Design

image.png

Type here table name now

image.png

@JeffJ625 

Hi Jeff,

 

If you look at the points#1 and 2 in my proposed solution, you are supposed to convert your data into an Excel Table and then rename the Excel Table as 'WebData" and then the query will work for you as desired as this query assumes that in your file there is an Excel Table called "WebData" which must be missing at present in your actual file.

To convert your data into an Excel Table, select all your data and then press Ctrl+T and it will convert your data into an Excel Table. Once your data is converted into an Excel Table, a Table Design Tab will appear in the Ribbon and if you click that and look at top right of the ribbon, you will have a TextBox to have Table Name and you can type the WebData in there and hit Enter, that will rename your Table as WebData.

@JeffJ625 

And much better, if you don't copy/paste from web but query the web, combine transformations suggested here with the initial query. If that's copy/paste perhaps it's worth to try query the web, finally it'll be one click solution - open the file, refresh all.

@Subodh_Tiwari_sktneer 

 

Subodh/Sergei,

 

Your suggestions have been most helpful. I was finally able to get the data into the right format but it is a tremendous amount of work.  I'm working off of a prospect list web site where I have to input the specific parameters for the companies I want to discover (for example, location, industry, yearly revenue, etc.).  For large listings, I'm able to see only 25 companies at a time.  It looks like this:

clipboard_image_0.png

I have to copy and paste each grouping of 25 into Excel and all of this info. goes into just one column.  When I've finally created a large enough list, I then run the Power Query that you've designed.  This is a lot of work because if each company doesn't have the exact same number of data points (in this case 7) the report is all jumbled and I have to go back and find where the missing data should go.  

 

Do you think I'm doing this in the most efficient way or is there a more economical way to go about this task.  I don't see how I can pull the info. right off the web site as I work because the web address just shows something like:  https://app.uplead.com/#.   I'm unsure if Excel can pull the exact info. that I've specifically collated on the site.

 

You gentlemen have been so very kind in your guidance and I sincerely appreciate it.

 

Regards,

Jeff

 

 

 

;lkjasdjf

 

@JeffJ625 

Jeff, that's not a free resource and it's hard to say what and how could be automated without playing with web site. It depends on many things, for example how the pagination is organised, by URL parameter or Java script changes pages without changing the URL. It could be some protection against connecting to their data. Etc., etc.

 

But in general yes, it could be possible to automate data pick-up from web site using Power Query. The evil is in the detail.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies