Forum Discussion

Jannis68's avatar
Jannis68
Frequent Visitor
8 years ago
Solved

Creating a new table in Power BI combining columns

I need to create a new table combining six columns into two columns and keep the identifiers. The exisiting table is:

 

question_idrespondent_idPos1Pos2Pos3Neg1Neg2Neg3
11x     
21x     
31x     
12xx     
22xx     
32x     

 

The new table should look like this:

 

question_idrespondent_idPositiveNegative

 

Positive should be a union of Pos1, Pos2, Pos3 and Negative Neg1, Neg2, Neg3

 

Any thoughts?

 

 

 

 

 

 

 

 

  • Hi Jannis68,

     

    If I understand you correctly, you should be able to use the Unpivot Columns option in Query Editor to unpivot the Pos columns and Neg columns separately to get the expected result in your scenario.

     

    For more details about how to Pivot and Unpivot with Power BI, you can refer to this article. :smileyhappy:

     

    Regards

7 Replies

  • v-ljerr-msft's avatar
    v-ljerr-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi Jannis68,

     

    If I understand you correctly, you should be able to use the Unpivot Columns option in Query Editor to unpivot the Pos columns and Neg columns separately to get the expected result in your scenario.

     

    For more details about how to Pivot and Unpivot with Power BI, you can refer to this article. :smileyhappy:

     

    Regards

  • hi, Jannis68

     

    When do you want to make that combination?
    When importing data or when creating a measure?
    Because depending on the moment you can use DAX functions or M functions.

    Of more details of the moment of this combination.

    • Jannis68's avatar
      Jannis68
      Frequent Visitor

      I have no preference wheter using on import or when creating a DAX.

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Icon for Community Champion rankCommunity Champion

        Jannis68

         

        Using DAX you can create a calculated Table

         

        Go to Modelling Tab>>>NEW TABLE and use this formula

         

        Table =
        SUMMARIZE (
            TableName,
            TableName[question_id],
            TableName[respondent_id],
            "Positive", SUM ( TableName[Pos1] ) + SUM ( TableName[Pos2] )
                + SUM ( TableName[Pos3] ),
            "Negative", SUM ( TableName[Neg1] ) + SUM ( TableName[Neg2] )
                + SUM ( TableName[Neg3] )
        )