Forum Discussion

gancw1's avatar
gancw1
Resolver II
3 years ago

Unpivot table

I have a quiz result in the following format

 

NameidQ11Q21
Staff A102TRUE1FALSE0
Staff B222FALSE0FALSE0
Staff C312TRUE1TRUE1

 

How do I unpivot the table to this format ?

 

NameidQuestionAnsScore
Staff A102Q1 TRUE1
Staff A102Q2 FALSE0
Staff B222Q1 FALSE0
Staff B222Q2 FALSE0
Staff C312Q1 TRUE1
Staff C312Q2 TRUE1

4 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    The columns with 0 and 1 in are redundant so you could remove those.

    Then Select the first 2 columns and Unpivot others.

    If you want, you can add a custom column to represent TRUE/FALSE as 1/0

    • gancw1's avatar
      gancw1
      Resolver II

      The true/false has no relation to the 1/0. It just happened that for these questions the true answer is the correct answer

  • In Power Query, highlight the Name ID column and choose unpivot other columns

  • My example was not very clear.  The '1' label is the maximum score possible for the question and true or false answer does not equal to 1 or 0 score

     

    Input 

    NameidQ1Max Score  Q2Max Score
    Staff A  102A  1C  0
    Staff B  222C  0B  1
    Staff C  3120A  0

     

    The desired output

    Name        id         QuestionAnsScore
    Staff A  102Q1 A  1
    Staff A  102Q2 C  0
    Staff B  222Q1 C  0
    Staff B  222Q2 B  1
    Staff C  312Q1 B  0
    Staff C  312Q2 A  1