+ Reply to Thread
Results 1 to 10 of 10

Transpose from columns to rows with Power Query

  1. #1
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Transpose from columns to rows with Power Query

    Hello all,

    I am real beginner in Power Query, knowing to do just basic stuffs... But right now i am in front of a problem where i think i can use Power Query, but i am blocked

    So i have the attached table and since in the end i will have to print a sheet with today values, i think that the "easiest" solution would be transpose in power query. But it seems harder than i believed in the first place.

    On the attached table, sheet "from" contains the table i have right now and sheet "to" contains the dates that i need to be exported by power query. I tried to user transpose with unpivot columns... but the result was a total mess

    In the end i will use a formula to get the dates from today, for all parts and print it.

    Do you think this can be done? Should i use another solution? Any help is highly appreciated.

    Thank you for your time
    Attached Files Attached Files

  2. #2
    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,777

    Re: Transpose from columns to rows with Power Query

    Use this M Code:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    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.

  3. #3
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Transpose from columns to rows with Power Query

    Thank you very much Ali,

    I will try to adapt it to my original table and see what i get

    Have yourself a great weekend.

  4. #4
    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,777

    Re: Transpose from columns to rows with Power Query

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Transpose from columns to rows with Power Query

    Dear Ali,

    In my original table i have a lot of different names as headers, for example 088888 659 Q.
    When i try to adapt your code into my original table i am getting the following error:
    Please Login or Register  to view this content.
    If i remove that column, i am getting the same error for another column, for example 075426 123 M

    Any ideea why is this happening?

    EDIT1:
    I tried to change Int64.Type to Text.Type, just for fun...
    I don't have any error now, but it only imports 92 row, instead of 177...

    EDIT2:
    i just realized that part of my table is not finished yet, so it contains no data yet. So i replace null with 0 in PQ and now i think that it imports all rows.
    I must see how can i change the code, in order to not sort column a from smallest to greatest.

    When you have time, please let me know if the changes i made are ok or are just silly
    Last edited by lofgren; 06-20-2020 at 03:58 PM.

  6. #6
    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,777

    Re: Transpose from columns to rows with Power Query

    I can’t say without seeing more realistic data in a sample.

  7. #7
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Transpose from columns to rows with Power Query

    I changed the names of the parts in sheet "from": Part 1 / B00 000 01 01 etc
    and
    in power query editor i changed "Part 1", etc, to B00 000 01 01 etc

    When i hit refresh, i receive a DataFormat.Error: We couldn't convert to Number.
    Attached Files Attached Files

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,874

    Re: Transpose from columns to rows with Power Query

    You have the Attribute Column as a Type Whole Number. It can't be and therefore you are getting a sort error. The column needs to be type "Text"

    Here is the revised Mcode making that column Text.

    Please Login or Register  to view this content.
    @Ali--Great piece of manipulation. Loved how you got it to sort by duplicating the column and removing the first character.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  9. #9
    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,777

    Re: Transpose from columns to rows with Power Query

    Thanks, Alan.

  10. #10
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Transpose from columns to rows with Power Query

    Everything works just fine

    Thank you both so much for your patience and help. You made my day!
    Have yourself a great weekend

+ 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. [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
  2. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  3. [SOLVED] Power Query - update particular columns
    By afgi in forum Excel Charting & Pivots
    Replies: 10
    Last Post: 02-16-2020, 06:41 PM
  4. Add custom rows and columns in Power Query
    By Shao85 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2019, 06:02 AM
  5. Custom Permutations Column in Power Query from two columns in the same Query
    By PaintPaddy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2019, 02:48 PM
  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. [SOLVED] Changing Power Query rows to columns on repeat cells.
    By beaglesBuddy in forum Excel General
    Replies: 3
    Last Post: 06-14-2017, 02:13 PM

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