Forum Discussion

New2PowerBI's avatar
New2PowerBI
Helper III
9 years ago
Solved

Difficulty in unpivoting Table

I would like to unpivot a table; but I can't seem to easily unpivot after following a couple of tutorials.  I suspect it has to do with the data as it is, I think I need to clean it up some more. 

Here is what I have in Power BI right now and what I'd like it to look like:

Existing data snapshotDesired table structure

Basically, for every course an employee has a record of (the non-null values), I would expect a row, with the Course Name and corresponding information, such as Grace Period, Frequency and Priority. 

 

Any help will be greatly appreciated.  :-)

  • Sean's avatar
    Sean
    9 years ago

    New2PowerBI

    1) Select Employee Name, Employee Number and Column 2 - Unpivot Other Columns

    2) Select Column 2 - Pivot Column - Values Column select Value - Don't Aggregate

    3) Rename Attribute Column (rearrange columns if you want)

    Hope this helps! :smileyhappy:

6 Replies

  • dkay84_PowerBI's avatar
    dkay84_PowerBI
    Microsoft Employee

    Can you please provide some sample data?  Typing everything from your screenshot is not fun...

    • New2PowerBI's avatar
      New2PowerBI
      Helper III

      Sure!

       

      Here is an example of what I brought in from Excel (a matrix).  The first two columns came in as one but I split them in Power BI, so there is the name and employee number now.

      Employee NameEmployee NumberColumn2010.100 development…etc020.200 development…etc500.100 course xyz name020.200 development…etc
      Anderson, Jesse123Frequency36121224
      Anderson, Jesse123Priority1351
      Anderson, Jesse123Grace Period3659060365

       

      Here is where I want to get to so I can build my visualizations:

       

      Course NameEmployee NameGrace PeriodFrequencyPriority
      010.100 development…etcAnderson, Jesse365361
      020.200 development…etcAnderson, Jesse90123
      500.100 course xyz nameAnderson, Jesse60125
      020.200 development…etcAnderson, Jesse365241

       

      Something tells me the third column ( in original) is what it's not liking, Column2.  I feel like that is what is throwing off the unpivot option and need to break this down into more than one step to get it right. 

       

      Thanks for your prompt response!  :-)

      • dkay84_PowerBI's avatar
        dkay84_PowerBI
        Microsoft Employee

        Got it:

         

        1. Duplicate your table
        2. In original table, remove column 2
        3. In orginal table, highlight the Employee Name and Number column, then right click and select "Unpivot Other Columns"
        4. In dupe table, remove the Employee Name, Number and Column 2 columns
        5. Demote headers
        6. Transpose table
        7. Rename columns (Course Name, Frequency, etc.)
        8. Create a Merge Query
          1. Select original table
          2. Select Merge Queries as New
          3. Select the "Attribute" column in original table
          4. Select "Course Name" column in dupe table
          5. Set Join Kind to Left Outer
        9. In Merged table, select Attribute column and remove dupes
        10. Remove the "Value" and "Attribute" column
        11. Expand the NewColumn column (with the nested tables)

        Done!