+ Reply to Thread
Results 1 to 21 of 21

Transform Table Structure

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

    Transform Table Structure

    I have an export out of our ERP system of cost centers.
    I am trying to transform this from a tabular structure to a horizontal structure based on the number of levels the node has.

    I have a mock-up attached. In this file, I have used the TRANSPOSE(UNIQUE) formula to get the number of levels in the node and an IF formula to transform the structure, this is highlighted in yellow. I'm sure this can be done in PQ, which I am decent at, but I need help completing this task.

    Any help or guidance would be appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    How about
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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

    Re: Transform Table Structure

    That is VERY useful but would like to do it in PQ so I can do additional transformation steps and join it with other tables in a model.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    In that case you will need to wait for somebody else, as I don't know PQ

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,928

    Re: Transform Table Structure

    I'd prepared this (doesn't need the level column):

    Please Login or Register  to view this content.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Transform Table Structure

    @AliGW This also works, but looking for a PQ solution

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,928

    Re: Transform Table Structure

    Yes, I realise that now.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,928

    Re: Transform Table Structure

    There's probably a more efficient way.

    M Code:


    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: Transform Table Structure

    @AliGW, This works, is there a way to fill down based on a condition?
    I want to fill down the text, but not the cost center numbers.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,928

    Re: Transform Table Structure

    You've lost me.

    What do you want to fill down, where and why?

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

    Re: Transform Table Structure

    Sorry, I have attached a sample of what I am trying to do.
    I highlighted the end result in blue.
    Last edited by AliGW; 06-20-2023 at 12:03 PM. Reason: Please do NOT quote unnecessarily!

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    I know you want to use PQ, but for the fun of it, another formula that just looks at col A
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Haven't sussed the fill down yet

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,928

    Re: Transform Table Structure

    I wish you'd said that before wes started!

    I am not the best at PQ, and there will be others better than I, but if I were doing it, I'd split each column conditionally (based on text or number), then fill down the text, then rejoin conditionally, but it would have to be done on each column separately.

    It is early evening here and I'm about to log off, but I'll throw up a call for help before I do.

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

    Re: Transform Table Structure

    My apologies, I assumed (incorrectly) that I could fill down and get my desired outcome. It was only after I had a working PQ option that I realized that this would not work.

    Thank you for all the time you put into this question.
    Last edited by AliGW; 06-20-2023 at 01:37 PM. Reason: Please do NOT quote unnecessarily.

  15. #15
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    With the lack of a PQ solution, here is a formula that will do what you want, if interested.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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

    Re: Transform Table Structure

    Quote Originally Posted by Fluff13 View Post
    With the lack of a PQ solution, here is a formula that will do what you want, if interested.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This solution accomplishes what I am trying to do. How would you even go about writing a formula such as this? It works!!
    Can it be altered to pull the cost center number into the last column? I have added this formula after I pasted the above formula:

    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Transform Table Structure

    I only used column A as data source. Output is on the first sheet

    Please Login or Register  to view this content.

  18. #18
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    How about
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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

    Re: Transform Table Structure

    Quote Originally Posted by Fluff13 View Post
    How about
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Excellent!! This solves my question, thank you so much for your help with this!!

  20. #20
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Transform Table Structure

    Glad to help & thanks for the feedback.

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

    Re: Transform Table Structure

    Please try

    Formula
    =LET(z,TEXTBEFORE(A2:A345," (",,,1),c,SEQUENCE(,6),d,VSTACK("|- ","< ",UNICHAR(12288)),y,IFNA(TEXTSPLIT(TEXTAFTER(z,d,c),d),"|"),
    SUBSTITUTE(TRANSPOSE(SCAN("",TRANSPOSE(y),LAMBDA(a,v,IF(v="",a,v)))),"|",))

    Power Query

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        
    Clean Table.TransformColumns(Source, {"Cost Center Hierarchy"each Text.Combine(Text.SplitAny(Text.BeforeDelimiter(_," ("),"|- <")) }),
        
    Split Table.SplitColumn(Clean"Cost Center Hierarchy"Splitter.SplitTextByDelimiter(" "), {"1".."6"}),
        
    Fill = List.Accumulate({{null,"|"},{"",null},{0},{"|",null}},Split,
            (
    s,l)=> if l{0}=0 then Table.FillDown(s,{"1".."6"}) else Table.ReplaceValue(s,l{0},l{1},Replacer.ReplaceValue,{"1".."6"}))
    in
        Fill 

+ 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: 4
    Last Post: 12-02-2018, 10:04 AM
  2. Replies: 40
    Last Post: 08-29-2018, 01:36 PM
  3. [SOLVED] Change data structure using Formula or Power Query ( Get & Transform)
    By chullan88 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-04-2017, 02:58 AM
  4. [SOLVED] Transform table to database structure
    By p3rlend in forum Excel General
    Replies: 4
    Last Post: 09-23-2016, 02:49 PM
  5. [SOLVED] How do I transform my table?
    By Catrosa in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-07-2015, 08:04 AM
  6. transform table vba
    By rhai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2012, 11:25 AM
  7. Transform table
    By asante_za in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2006, 05:15 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