+ Reply to Thread
Results 1 to 8 of 8

Stacked Data Clean Up + Power Query

  1. #1
    Forum Contributor
    Join Date
    11-29-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    104

    Stacked Data Clean Up + Power Query

    I have a data set with Names in addresses in a stacked format. There is a column within the data set that indicates how many lines the record has. For example, some records have 3 lines, some have 4 ETC.
    My initial thought was to use Power Query, add an index column, then use the Modulo function, but that seems to work for data that has a defined set number of rows.

    Is there a way to unstack this data using the modulo function or some other means?

    I have attached a sample of the data, please see attached.

    Any help or guidance is appreciated,
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Stacked Data Clean Up + Power Query

    Not sure it's what you are looking for, but using something like this to get a row reference you can then get the data using INDEX:

    =IF(ROW(H2)>=SUM(Table1[Number-Of_Lines]+0),"",H2+IF(ROW(H2)<=SUM($D$2:INDEX($D:$D,H2)+0),0,1))

    I had to manually set the first row to 2, but that shouldn't be too hard. See attached example.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    11-29-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    104

    Re: Stacked Data Clean Up + Power Query

    Thank you for taking the time to review this. I have looked at the file, and I am unsure how different it is from what I am starting with?
    I will add an ideal outcome to the file and repost an edited file.
    Attached Files Attached Files
    Last edited by jrean042; 04-05-2022 at 01:45 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Stacked Data Clean Up + Power Query

    Sorry, I thought you meant you wanted each row repeated based on the value in the "number of lines" column. So you're just using column_5 here?

  5. #5
    Forum Contributor
    Join Date
    11-29-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    104

    Re: Stacked Data Clean Up + Power Query

    That is correct. I need to unstack column_5, but column "Number-Of_Lines" will likely be the helper column to get an idea of how many pieces of information there are per record.
    My apologies, I should have been more clear in my question.

    Thank you again,

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Stacked Data Clean Up + Power Query

    Please try PQ

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        
    RemovedOtherColumns Table.SelectColumns(Source,{"Column_1""Number-Of_Lines""Column_5"}),
        
    PivotedColumn Table.Pivot(RemovedOtherColumns, List.Distinct(RemovedOtherColumns[#"Number-Of_Lines"]), "Number-Of_Lines", "Column_5"),
        
    RemovedColumns Table.RemoveColumns(PivotedColumn,{"Column_1"})
    in
        RemovedColumns 
    or formula
    H3
    =IFERROR(INDEX($E$3:$E$23,AGGREGATE(15,6,ROW($D$3:$D$23)/(AGGREGATE(15,6,ROW($D$3:$D$23)/($D$3:$D$23="1"),ROWS(H$3:H3))=LOOKUP(ROW($D$3:$D$23),ROW($D$3:$D$23)/($D$3:$D$23="1"))),COLUMNS($H3:H3))-ROW($D$2)),"")
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Stacked Data Clean Up + Power Query

    Ok, I've updated my formula version. In H11 (copied down):

    =IFERROR(INDEX($E:$E,SMALL(IF(Table1[Number-Of_Lines]+0=COLUMN(H9)-COLUMN($H$9)+1,ROW(Table1[Number-Of_Lines]),""),ROW(H9)-ROW($H$9)+1)),"")

    In I11 (copied across and down):

    =IFERROR(IF(INDEX($D:$D,SMALL(IF(Table1[Number-Of_Lines]+0=1,ROW(Table1[Number-Of_Lines]),""),ROW($H9)-ROW($H$9)+1)+COLUMN(I9)-COLUMN($H$9))+0=COLUMN(I9)-COLUMN($H$9)+1,INDEX($E:$E,SMALL(IF(Table1[Number-Of_Lines]+0=1,ROW(Table1[Number-Of_Lines]),""),ROW($H9)-ROW($H$9)+1)+COLUMN(I9)-COLUMN($H$9)),""),"")
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    11-29-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    104

    Re: Stacked Data Clean Up + Power Query

    These are both GREAT answers! And both accomplish what I am trying to do.
    Thank you very much for all your help!!

+ 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. Power Query: Add Data to a Query
    By andrewc in forum Excel General
    Replies: 1
    Last Post: 09-11-2020, 01:46 PM
  2. Replies: 10
    Last Post: 06-25-2020, 12:19 AM
  3. [SOLVED] How to access data via VBA from a Connection Only Power Query query.
    By MLAN_75 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2020, 11:45 AM
  4. [SOLVED] Power Query - excel formula translation into Power Query
    By afgi in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 02-19-2020, 03:38 AM
  5. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  6. 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
  7. 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

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